[R] error in rowSums in data.table

2013-05-30 Thread Camilo Mora
hi: I have a datatable with two columns (see below) and I want to create another column that adds the values of the rows in the first two columns. I am trying this: DT[ , col3 :=rowSums(.SD, na.rm = TRUE), .SDcols = c(col1,col2)] but I get this error: Error in inherits(x, data.frame) :

Re: [R] error in rowSums in data.table

2013-05-30 Thread Rainer Schuermann
On Thursday 30 May 2013 02:57:04 Camilo Mora wrote: do you know why is this? or is there another way to sum by row in a given number of columns? Without data.table: x - structure(list(col1 = c(NA, 0, -0.015038, 0.003817, -0.011407 ), col2 = c(0.003745, 0.007463, -0.007407, -0.003731,

[R] Error in rowSums

2010-08-12 Thread Amit Patel
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

Re: [R] Error in rowSums

2010-08-12 Thread Erik Iverson
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)

Re: [R] Error in rowSums

2010-08-12 Thread TGS
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

Re: [R] Error in rowSums

2010-08-12 Thread Peter Ehlers
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