[R] error in rowSums in data.table

Camilo Mora cmora at dal.ca
Thu May 30 07:57:04 CEST 2013


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") : object '.SD' not found

do you know why is this? or is there another way to sum by row in a  
given number of columns?

Cheers,

Camilo




#        col1      col2      col3
#1:        NA  0.003745  0.003745
#2:  0.000000  0.007463  0.007463
#3: -0.015038 -0.007407 -0.022445
#4:  0.003817 -0.003731  0.000086
#5: -0.011407 -0.007491 -0.018898



More information about the R-help mailing list