Reputation: 688
I want to transpose this data frame from
Cat Group Rank
229 A 1
229 C 2
230 B 1
230 E 2
231 F 1
231 D 2
.. .. ..
and make it look like
Cat 1 2
229 A C
230 B E
231 F D
.. .. ..
I've used dcast
from reshape2
Table<- dcast(Table, Cat ~ Rank , value.var = 'Group')
but I get the following when executing:
Aggregation function missing: defaulting to length
and the data frame converts to
Cat 1 2
229 1 1
230 1 1
231 1 1
.. .. ..
Any ideas how can I resolve this?
Upvotes: 1
Views: 333
Reputation: 887118
We can create a sequence column for the duplicates and it should work
library(data.table)
dcast(setDT(Rank2), Cat + rowid(Rank) ~ Rank, value.var = 'Group')
Upvotes: 1