Skip to content
Prev 244814 / 398513 Next

inconsistency with cor() - "x must be numeric"

Hi,

I can certainly understand not wanting to be long winded, and no
damage done.  Here's a link to the R news file:
http://cran.stat.ucla.edu/src/base/NEWS   and if you search in your
browser for "cor() and cov()" you should find what happened.

At any rate, I could not fully check your code because:  object
'accessibility_data' not found, but my guess would be that you created
a matrix (if inadvertently), and at least one of the columns had some
character data in it, which would push *all* the data to character
class (even though a particular column may be numeric data it is not
stored as character).  Previously I think cor() did not check this,
and would silently convert using as.numeric().

I would look at:

str(acc_averages)

and I bet you will find that it is not numeric.  If this is the case,
one fix would be:

correlation = cor(as.numeric(acc_averages[,2]),
gene_densities$avg_density[1:23])

probably a better fix would be to initiate acc_averages as a
data.frame rather than with c(), that way it can store different types
of data without moving everything up the hierarchy of classes.  To see
what I mean look at ?rbind under the heading "Values" the second
paragraph.

Cheers,

Josh
On Mon, Dec 13, 2010 at 2:23 PM, Justin Fincher <fincher at cs.fsu.edu> wrote: