This is my data.frame:
library(data.table)
df<- fread('
predictions Label
3 A
4 B
5 C
1 A
2 B
3 C
')
Desired Output:
A B C
3 4 5
1 2 3
I am trying DesiredOutput<-dcast(df, Label+predictions ~ Label, value.var = "predictions")
with no success. Your help is appreciated!
Maybe the base R function
unstack
is the cleanest solution:Note that this returns a data.frame rather than a data.table, so if you want a data.table at the end:
will return a data.table.