Re: [R] Removing NAs from matrix

2013-12-01 Thread arun
Hi, Try: ?rowMeans rowMeans(mat,na.rm=TRUE) A.K. On Sunday, December 1, 2013 1:15 PM, Amie Hunter wrote: Hello R users, I'm new to R so apologies if this question seems simple. I have a matrix which is 35000 columns by 35000 rows and I’m wanting to work out the mean of each row. I've tried

Re: [R] Removing NAs from matrix

2013-12-01 Thread Rui Barradas
Hello, Your code corrected would be mean.matrix[, 1] <- apply(mat, 1, mean, na.rm = TRUE) (No need for the for loop). Even better would be to avoid loops and use the base R function ?rowMeans. mean.matrix[, 1] <- rowMeans(mat, na.rm = TRUE) Hope this helps, Rui Barradas Em 01-12-2013 12:16

[R] Removing NAs from matrix

2013-12-01 Thread Amie Hunter
Hello R users, I'm new to R so apologies if this question seems simple. I have a matrix which is 35000 columns by 35000 rows and I’m wanting to work out the mean of each row. I've tried using the code below on a smaller version of the matrix, but receive an error: > mat   [,1]  [,2] [,