[R] summing columns with NAs present

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Fri Aug 5 20:01:01 CEST 2011


Hello!

I have a data frame with some NAs.
test<-data.frame(a=c(1,2,NA),b=c(10,NA,20))

I need to sum up values in 2 variables. However:
test$a+test$b
procudes NAs in rows that have NAs.

How could I sum up columns while ignoring NAs (the way the function
sum(..., na.rm=T) works?
Thank you!
-- 
Dimitri Liakhovitski
marketfusionanalytics.com



More information about the R-help mailing list