RandomForest has returned object, prd, which is class numeric with indices:
> prd
298 252 373 117 0 16 442 74
4397.9232 1826.1264 1787.1963 1388.8097 1075.7217 873.9856 1602.7068 1775.1237
class(prd)
[1] "numeric"
I want to do a correlation test, which means getting obs in the same format. Currently, obs is a one-column data frame:
> obs
e2004MeanY
298 4261
252 1821
373 1710
117 1138
How do I convert obs to the correct format? I can’t figure out how to tie the indices to the values in a numeric.
You can subset a data frame using
[which, as the default isdrop = TRUEwill drop the empty dimension thus going from a 1 column data frame to a numeric vector. E.g.If the losing of the row names is an issue then add them back as the
namesof the vector:Of course, this isn’t an issue if you use a temporary object when you call
cor(), for example: