[R-sig-Epi] NA:s in stat.table (library Epi)

Lauri Nikkinen lauri.nikkinen at iki.fi
Tue Nov 6 12:11:07 CET 2007


#Hello,

#I have a data.frame similar to this:

library(Epi)
Aye <- sample( c("Yes","Si","Oui"), 177, replace=TRUE )
Bee <- sample( c("Hum","Buzz"), 177, replace=TRUE )
Sea <- sample( c("White","Black","Red","Dead"), 177, replace=TRUE )
temp <- data.frame(Aye, Bee, Sea)
temp$Sea[temp$Sea == "Red"] <- NA
str(temp)

drop.levels <- function(dat){
  dat[] <- lapply(dat, function(x) x[,drop=TRUE])
  return(dat)
}
temp <- drop.levels(temp)

#I can calculate count and percentages using stat.table:

stat.table(Sea, list(count(), percent(Sea)), data=temp)

# -----------------------------
# Sea     count() percent(Sea)
# -----------------------------
# Black        39         31.2
# Dead         32         25.6
# White        54         43.2
# -----------------------------

#But I would like to include count and percet of NA:s, like this
# -----------------------------
# Sea     count() percent(Sea)
# -----------------------------
# Black        39         22.0
# Dead         32         18.1
# White        54         30.5
# NA            52         29.4
# -----------------------------

#Is that possible using stat.table?

#Thanks
#Lauri



More information about the R-sig-Epi mailing list