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

BXC (Bendix Carstensen) bxc at steno.dk
Tue Nov 6 13:48:11 CET 2007


or:
 stat.table(zz<-factor(Sea,exclude=NULL), list("N"=count(),
"%"=percent(zz)), data=temp) 

> -----Original Message-----
> From: lauri.nikkinen at gmail.com 
> [mailto:lauri.nikkinen at gmail.com] On Behalf Of Lauri Nikkinen
> Sent: Tuesday, November 06, 2007 1:16 PM
> To: BXC (Bendix Carstensen)
> Cc: r-sig-epi at stat.math.ethz.ch
> Subject: Re: [R-sig-Epi] NA:s in stat.table (library Epi)
> 
> Sorry, I got it:
> 
> stat.table(factor(Sea,exclude=NULL), list(count(), 
> percent(factor(Sea, exclude=NULL))), data=temp)
> 
> Best regards,
> Lauri
> 
> 2007/11/6, Lauri Nikkinen <lauri.nikkinen at iki.fi>:
> > Thanks Bendix,
> >
> > Now when I type:
> >
> > > stat.table(factor(Sea,exclude=NULL), list(count(), percent(Sea)), 
> > > data=temp)
> >
> > I get:
> > -----------------------------
> > NA      count() percent(Sea)
> > -----------------------------
> > Black        50        100.0
> > Dead         39        100.0
> > White        41        100.0
> > NA           47        100.0
> > -----------------------------
> >
> > All the percentages are 100 % in each level of factor Sea. Is it 
> > possible to get correct percentages?
> >
> > Regards,
> > Lauri
> >
> > 2007/11/6, BXC (Bendix Carstensen) <bxc at steno.dk>:
> > > The key to this buried in the exclude= argument to factor() !
> > > See the help page for factor:
> > >
> > > ?factor
> > >
> > > This will work:
> > >
> > > stat.table(factor(Sea,exclude=NULL), list(count(), percent(Sea)),
> > > data=temp)
> > >
> > > Best,
> > > Bendix
> > >
> > > > -----Original Message-----
> > > > From: r-sig-epi-bounces at stat.math.ethz.ch
> > > > [mailto:r-sig-epi-bounces at stat.math.ethz.ch] On Behalf Of Lauri 
> > > > Nikkinen
> > > > Sent: Tuesday, November 06, 2007 12:11 PM
> > > > To: r-sig-epi at stat.math.ethz.ch
> > > > Subject: [R-sig-Epi] 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
> > > >
> > > > _______________________________________________
> > > > R-sig-Epi at stat.math.ethz.ch mailing list 
> > > > https://stat.ethz.ch/mailman/listinfo/r-sig-epi
> > > >
> > >
> >
> 



More information about the R-sig-Epi mailing list