Skip to content
Prev 320233 / 398503 Next

count NAs with aggregate

Hello,

The problem seems to be with the formula interface.

# Make up some data
var1 <- rnorm(100)
var2 <- rnorm(100)
var3 <- rnorm(100)
subject <- sample(4, 100, replace = TRUE)
time <- sample(10, 100, replace = TRUE)
var1[sample(100, 10)] <- NA
var2[sample(100, 10)] <- NA
var3[sample(100, 10)] <- NA

mydataset <- data.frame(var1, var2, var3, subject, time)

count_nas <- function(arg1) {
   return(sum(is.na(arg1)))
}

aggregate(mydataset[, 1:3], list(mydataset$subject, mydataset$time), FUN 
= count_nas)


Hope this helps,

Rui Barradas

Em 25-03-2013 15:40, Timo Stolz escreveu: