R tricks >

Convert data from long to wide format

Using tidyr::spread():

library(tidyr)

wide <- spread(ChickWeight, Chick, weight)

Using reshape2::dcast():

library(reshape2)

wide <- dcast(ChickWeight, Time + Diet ~ Chick, value.var = "weight")