How to Transpose Data frame as row to column

could someone help me on the below transformation plz

name<- c("abc", "abc", "abc", "xyz", "xyz", "xyz")
type<- c(1, 2, 3, 1,2,3)
count<-c(30,50,39, 40,20,60)

df<-data.frame(name, type, count)

i wanted to convert the above data frame as below table

name 1 2 3
abc 30 50 39
xyz 40 20 60

tidyr::spread(df, type, count)

1 Like

thanks a lot that is what exactly i was looking for.. :slight_smile:

If you want to do it with only base packages:

xtabs(count ~ name + type, data = df)

Note, though, that the output here is an array, not a data frame.

1 Like