I am trying to transpose a two column data table. The dt is of something like this.
access.id | data
1 0
1 0
2 150
... ...
What I want to have is something like this.
access.id | V1 | V2
1 0 0
2 150 ...
I have tried different approaches but I can't seem to get the result I want.
test[, lapply(.SD, .fun=function(dt) { return (transpose(dt)) }) , by = access.id]
or
test[, lapply(.SD, .fun=function(dt) { return (transpose(dt[data])) }) , by = access.id]
or
test[, .SD[, transpose(data)] , by = access.id]
The above give me an error: "Error in transpose(dt) : l must be a list."
test[, lapply(.SD, .fun=function(dt) { return (transpose(dt$data)) }) , by = access.id]
This gives the error: ' Error in dt$data : $ operator is invalid for atomic vectors"
test[, .SD[, t(data)] , by = access.id]
This works but gives me the exact same data table.
When I tried substituting t(data) for sum(data), it worked and gave me the sum of the data columns. I am unsure why what I tried doesn't work.
So my question is, how do I transpose this data table?