I am trying to use dcast()
, but I can't figure out why I get this error:
"Error : value.var (mpg) not found in input". Dcast can't seem to find "mpg" which I made a measure.vars in the melt function.
Can you guys help me?
Here is my code:
data("mtcars")
install.packages("reshape")
library(reshape)
install.packages("reshape2")
library(reshape2)
mdata <- melt(mtcars, id=c("gear","cyl"), measure.vars = c("mpg","hp"))
castData <- dcast(mdata, gear ~ cyl, value.var="mpg")