Hi I am trying to calculate the row sums of a matrix i have created The matrix ( FeaturePresenceMatrix) has been created by 1) Read csv 2) Removing unnecesarry data using [-1:4,] command 3) replacing all the NA values with as.numeric(0) and all others with as.numeric (1) When I carry out the command TotalFeature <- rowrowSums(FeaturePresenceMatrix, na.rm = TRUE) I get the following error. Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) : 'x' must be numeric Any tips onhow I can get round this? Thanks in Advance Amit
Amit Patel wrote:> Hi > > I am trying to calculate the row sums of a matrix i have created > The matrix ( FeaturePresenceMatrix) has been created by > > 1) Read csv > 2) Removing unnecesarry data using [-1:4,] command > 3) replacing all the NA values with as.numeric(0) and all others with as.numeric > (1) > > When I carry out the command > > TotalFeature <- rowrowSums(FeaturePresenceMatrix, na.rm = TRUE) > > I get the following error. > > Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) : > 'x' must be numeric > > Any tips onhow I can get round this?Yes, follow the posting guide and give the list a reproducible example. We don't know a critical piece of information, the class of your data. We know it's *not* numeric though, which is what it needs to be. Use ?class, ?str, and possibly give us a small sample with ?dput. That way, we can reproduce the error.
Yes, please do as Erik said in the future but here's one way to do it. (A <- matrix(data = rnorm(n = 9, mean = 0, sd = 1), nrow = 3, ncol = 3, byrow = FALSE, dimnames = NULL)) matrix(rowSums(A)) On Aug 12, 2010, at 11:28 AM, Amit Patel wrote: Hi I am trying to calculate the row sums of a matrix i have created The matrix ( FeaturePresenceMatrix) has been created by 1) Read csv 2) Removing unnecesarry data using [-1:4,] command 3) replacing all the NA values with as.numeric(0) and all others with as.numeric (1) When I carry out the command TotalFeature <- rowrowSums(FeaturePresenceMatrix, na.rm = TRUE) I get the following error. Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) : 'x' must be numeric Any tips onhow I can get round this? Thanks in Advance Amit ______________________________________________ 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.
Another suggestion: compare -1:4 with -(1:4) -Peter Ehlers On 2010-08-12 12:28, Amit Patel wrote:> Hi > > I am trying to calculate the row sums of a matrix i have created > The matrix ( FeaturePresenceMatrix) has been created by > > 1) Read csv > 2) Removing unnecesarry data using [-1:4,] command > 3) replacing all the NA values with as.numeric(0) and all others with as.numeric > (1) > > When I carry out the command > > TotalFeature<- rowrowSums(FeaturePresenceMatrix, na.rm = TRUE) > > I get the following error. > > Error in rowSums(FeaturePresenceMatrix, na.rm = TRUE) : > 'x' must be numeric > > Any tips onhow I can get round this? > > Thanks in Advance > Amit