I'm using the below method to cast variables in a dataframe from long to wide format. However, I'm looking for an alternative way, using another package. Any help is much appreciated?
subject <- c(1:10, 1:10)
condition <- c(rep(1,10), rep(2,10))
value <- c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5)
rating <- c(1, 3, 5, 2, 3, 5, 6, 7, 5, 3, 5, 7, 3, 6, 3, 5, 6, 7, 7, 8)
df <- data.frame(subject, condition, value, rating)
library(data.table)
df_wide <- dcast(setDT(df), subject ~ condition, value.var=c("rating", "value"))