Skip to content
Back to formatted view

Raw Message

Message-ID: <ba8c09910711060311w5973aba7w8847ab82b1ed6123@mail.gmail.com>
Date: 2007-11-06T11:11:07Z
From: Lauri Nikkinen
Subject: NA:s in stat.table (library Epi)

#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