Re: [R] Transforming relational data

2011-02-23 Thread mathijsdevaan
Thanks Matthew that worked great. What a great forum this is: I am learning a lot! PS. I am now running both solutions on two similar computers. Let's see which is fastest. -- View this message in context: http://r.789695.n4.nabble.com/Re-Transforming-relational-data-tp3307449p3321214.html

Re: [R] Transforming relational data

2011-02-23 Thread Gabor Grothendieck
On Wed, Feb 23, 2011 at 10:46 AM, mathijsdevaan mathijsdev...@gmail.com wrote: Thanks Matthew that worked great. What a great forum this is: I am learning a lot! PS. I am now running both solutions on two similar computers. Let's see which is fastest. If your data is small its pointless to

Re: [R] Transforming relational data

2011-02-22 Thread mathijsdevaan
Hi Matthew, thanks for your help. There are some things going wrong still. Consider this (slightly extended) example: library(data.table) DT = data.table(read.table(textConnection(A B C 1 1 a 1999 2 1 b 1999 3 1 c 1999 4 1 d 1999 5 2 c 2001 6 2 d 2001 7 3 a 2004 8 3

Re: [R] Transforming relational data

2011-02-22 Thread Matthew Dowle
With the new example, what is the full output, and what do you need instead? Was it correct for the previous example? Matthew mathijsdevaan mathijsdev...@gmail.com wrote in message news:1298372018181-3318939.p...@n4.nabble.com... Hi Matthew, thanks for your help. There are some things going

Re: [R] Transforming relational data

2011-02-22 Thread mathijsdevaan
The output for the new example should be: project v 1 0 2 0.5 3 1.5 4 0.5 The output you calculated was correct for the v per year, but the v per group would be incorrect. I think the problem lies in the fact that expand.grid(B,B) doesn't take into account that combinations of B can only

Re: [R] Transforming relational data

2011-02-22 Thread Gabor Grothendieck
On Mon, Feb 14, 2011 at 12:22 PM, mathijsdevaan mathijsdev...@gmail.com wrote: Hi, I have a large dataset with info on individuals (B) that have been involved in projects (A) during multiple years (C). The dataset contains three columns: A, B, C. Example:   A  B  C 1 1  a  1999 2 1  b  

Re: [R] Transforming relational data

2011-02-22 Thread mathijsdevaan
Gabor, that worked great! I was unaware of the sqldf package, but it is great for data manipulation. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Re-Transforming-relational-data-tp3307449p3320067.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] Transforming relational data

2011-02-22 Thread Matthew Dowle
Thanks. How about this? DT$B = factor(DT$B) firststep = DT[,cbind(expand.grid(B,B),v=1/length(B),C=C[1]),by=A][Var1! =Var2] setkey(firststep,Var1,Var2,C) firststep = firststep[,transform(.SD,cv=cumsum(v)),by=list(Var1,Var2)] setkey(firststep,Var1,Var2,C) DT[,

Re: [R] Transforming relational data

2011-02-21 Thread Matthew Dowle
Thanks for the attempt and required output. How about this? firststep = DT[,cbind(expand.grid(B,B),v=1/length(B)),by=C][Var1!=Var2] setkey(firststep,Var1,Var2,C) firststep = firststep[,transform(.SD,cv=cumsum(v)),by=list(Var1,Var2)] setkey(firststep,Var1,Var2,C) DT[,

Re: [R] Transforming relational data

2011-02-18 Thread mathijsdevaan
OK, for the last step I have tried this (among other things): library(data.table) DT = data.table(read.table(textConnection(A B C 1 1 a 1999 2 1 b 1999 3 1 c 1999 4 1 d 1999 5 2 c 2001 6 2 d 2001 7 3 a 2004 8 3 b 2004 9 3 d 2004),head=TRUE,stringsAsFactors=FALSE))

Re: [R] Transforming relational data

2011-02-17 Thread mathijsdevaan
Thanks for helping me out so generously. After reading the vignettes and the other info I still have a question (sorry I am a R novice): I am not so much trying to construct time series (although it comes very close). Rather for each pair (Bi,Bj) in project (An) I am trying to sum up the values

Re: [R] Transforming relational data

2011-02-17 Thread Matthew Dowle
Mathijs, To my eyes you seem to have repeated back what is already done. More R and less English would help. In other words if it is not 2.5 you need, what is it? Please provide some input and state what the output should be (and what you tried already). Matthew -- View this message in

Re: [R] Transforming relational data

2011-02-15 Thread Matthew Dowle
Hello. One (of many) solution might be: require(data.table) DT = data.table(read.table(textConnection(A B C 1 1 a 1999 2 1 b 1999 3 1 c 1999 4 1 d 1999 5 2 c 2001 6 2 d 2001),head=TRUE,stringsAsFactors=FALSE)) firststep =

[R] Transforming relational data

2011-02-14 Thread mathijsdevaan
Hi, I have a large dataset with info on individuals (B) that have been involved in projects (A) during multiple years (C). The dataset contains three columns: A, B, C. Example: A B C 1 1 a 1999 2 1 b 1999 3 1 c 1999 4 1 d 1999 5 2 c 2001 6 2 d 2001 7 3 a 2004 8 3 c 2004