[R] Need help using Melt and cast to compute correlation for a cross tabulation

Walter Anderson wandrson01 at gmail.com
Thu Mar 1 18:23:37 CET 2012


I have a data frame with a number of observed and predicted values by 
classification as shown below:

         Count   Volume  FCLASS
1      55000   60000   Grade Separated
2      43000   39000   Grade Separated
3      26000   26500   Major Arterial
4      19500   20000   Major Arterial
...

There are four classes here: Grade Separated, Major Arterial, Minor 
Arterial, and Collector

I am looking to compute the following information

FCLASS                   cor(Count,Volume)
Grade Separated   0.999
Major Arterial         0.999
Minor Arterial         0.999
Collector                 0.999

I am attempting to use the following commands to achieve this:

library(reshape)
tmp <- melt(dataframe)
cast(tmp, FCLASS ~ variable, function(Count, Volume) cor(Count, Volume))

but this is generating:  Error in is.data.frame(y) : argument "Volume" 
is missing, with no default

Any suggestions?

Walter Anderson



More information about the R-help mailing list