[R] Problem with rowMeans()
Erik Iverson
iverson at biostat.wisc.edu
Thu Jun 12 22:55:09 CEST 2008
Hello -
ss wrote:
> Hi all,
>
> I have a matrix called 'data', which looks like:
>
>> data[1:4,1:4]
> Probe_ID Gene_Symbol M1601 M1602
> 1 A_23_P105862 13CDNA73 -1.6 0.16
> 2 A_23_P76435 15E1.2 0.18 0.59
> 3 A_24_P402115 15E1.2 1.63 -0.62
> 4 A_32_P227764 15E1.2 -0.76 -0.42
>> dim(data)
> [1] 23963 85
>
Do you really have a matrix, or a data.frame?
Try
> class(data)
> What I want to do is to make a new matrix called 'data2', which would be
> transformed
> by subtracting the mean of each row from matrix 'data'. There are some 'NA's
> in the
> matrix and I do want to keep it.
See ?scale
>
> I tried to take 'mean's from each row first by using:
>
> a<- rowMeans(data[,3:85],na.rm = FALSE)
>
> but I got:
>
>> a<- rowMeans(data[,3:85],na.rm = FALSE)
> Error in rowMeans(data[, 3:85], na.rm = FALSE) : 'x' must be numeric
>
> Can anybody suggest me how to get around this?
Figure out what you are giving the rowMeans function.
If you really have a matrix, then
all(apply(data[,3:85], 2, class) == "numeric") should be TRUE.
>
> Thank you very much!
>
> Allen
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list