How to reshape a data frame from wide to long in r, day wide to long in r or long to wide format. More details:
code:
library(reshape2)
cars =mtcars
converting from wide to long format
carsmelt = melt(cars, id.vars = c("mpg", "cyl"))
head(carsmelt)
tail(carsmelt)
revert back from long to wide data
carswide_format = dcast(carsmelt, mpg + cyl ~ variable)
head(carswide_format)
carsmelt2 = melt(cars)