This question already has an answer here:
- How to reshape data from long to wide format 11 answers
I am trying to reshape an example dataframe by the following.
df<-data.frame(market = c("a","b","c","a","b","c"),companyName = c("foo","foo","foo", "bar","bar","bar"), val = seq(1,6))
require(reshape)
dfNew <- cast(df,market ~ companyName+companyName)
To generate:
market company 1 company 2
1 a 1 4
2 b 2 5
3 c 3 6
But I get this error:
Using val as value column. Use the value argument to cast to override this choice
Error in `[.data.frame`(data, , variables, drop = FALSE) :
undefined columns selected
reshape
andreshape2
are both deprecated packages at this point. If you use Hadley's latest version,tidyr
: