Tuesday, 10 September 2013

transpose-like procedure in data.table

transpose-like procedure in data.table

I asked a similar yet different question before (here)
Now I wanna change this dataset:
dt <- data.table(a=c("A","A","A"),b=1:3,c=c(0,1,0))
dt
a b c
1: A 1 0
2: A 2 1
3: A 3 0
to this one:
a 1 2 3
1: A 0 1 0
So values of column "b" should become columns each with the value of
column "c". Values of "a" can be seen as participants (here just one
Person ("A"). The original dataset continues with multiple values of B and
so on. After "transposing", column "a" should include unique values (e.g.
A,B,C etc)
Any suggestions?

No comments:

Post a Comment