Hi all,

I was experiencing a similar problem with some code which uses the package
maCorrPlot (BioConductor)
http://www.bioconductor.org/packages/2.6/bioc/html/maCorrPlot.html
to compute the correlation between different variables. This code was
working
apparently fine under R 2.9 (but it was raising warning messages!) and the
same was not working under R 2.11.

A simple example was:

1.> library(maCorrPlot)
2.> m <- as.matrix(read.table(fileIn, header=TRUE, sep='\t'))
3.> m <- m[,2:ncol(m)]
4.> corr.m <-  CorrSample(m,np=1000)

The WARNING (in version 2.9)  was: "NAs introduced by coercion"
The ERROR in version 2.11 was: "Error in cor(g1, g2, use = "pairwise") : 'x'
must be numeric"

My problem was that the matrix (that I was reading and loading into m in
line 2) contained a first column with the row names (character strings).
Therefore, although it was not being taken into account for computing
correlation in line 4, (because this column was "removed" from m in line 3),
it was forcing a casting to string when reading the whole m matrix. I.e,
reading this first column as part of the values of the matrix makes
as.matrix(read.table(..)) produce a matrix of char strings.

Simply changing line 2 with:
2'. > m <- as.matrix(read.table(fileIn, header=TRUE, sep='\t',row.names=1))
and removing line 3 above, the code works (both in R 2.10 and R 2.11)
because there are only numeric values in the matrix and
as.matrix(read.table(..)) now converts the values to numeric by default.


I couldn't check John M. Quick's site, but I think the problem is that
somehow you are loading char string values in your matrix "datavar".

Carlos


On 10/05/2010 7:36 AM, Ruben Garcia Berasategui wrote:

 Dear all,
when trying to replicate John M. Quick's example for correlations between
multiple variables posted on:

http://rtutorialseries.blogspot.com/2009/11/r-tutorial-series-zero-order.html

with R 2.11.0 (GUI 1.33) using my MacBook Pro with OX X 10.5.8 I got the
following error message


datavar<-read.csv("dataset_readingTests.csv")
cor(datavar)

Error in cor(datavar) : 'x' must be numeric

The funny thing is that when I tried to do the same example using R 2.10.1, it
worked fine.
Any ideas regarding how to solve this problem?

I would think the first step would be to ask Mr. Quick what's wrong.

Duncan Murdoch

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to