View source: R/datautilities.R
rowsumna | R Documentation |
row sums of an array or matrix correctly accounting for NA
rowsumna(x)
x |
a numeric array or matrix |
returns NA only of all are NA, otherwise returns sum of non missing value
calls sumna. Compare to rowSum(x, na.rm=TRUE) which returns 0 if all values are NA
x<-c(rep(NA, 5))
y<-c(rep(NA, 3), 1, 2)
rowSums(cbind(x, y), na.rm=TRUE)
rowsumna(cbind(x, y))
library(dplyr)
xdat<-data.frame(x=c(rep(NA, 5)), y=c(rep(NA, 3), 1, 2), z=c(NA, 1:4))
xdat %>%
mutate(q=rowsumna(cbind(x, y, z)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.