Debian Codegraph @

man/percent.Rd

raw
1 \name{percent}
2 \alias{percent}
3 \alias{percent.default}
4 \alias{percent.logical}
5 \title{Table of Percentages with Percentage Base}
6 \description{
7 \code{percent} returns a table of percentages along with
8 the percentage base. It will be useful
9 in conjunction with \code{\link{Aggregate}} or \code{\link{genTable}}.
10 }
11 \usage{
12 percent(x,\dots)
13 \method{percent}{default}(x,weights=NULL,total=!(se || ci),
14 se=FALSE,ci=FALSE,ci.level=.95,
15 total.name="N",perc.label="Percentage",\dots)
16 \method{percent}{logical}(x,weights=NULL,total=!(se || ci),
17 se=FALSE,ci=FALSE,ci.level=.95,
18 total.name="N",perc.label="Percentage",\dots)
19 }
20 \arguments{
21 \item{x}{a numeric vector or factor.}
22 \item{weights}{a optional numeric vector of weights of the same length as \code{x}.}
23 \item{total}{logical; should the total sum of counts from which the percentages are
24 computed be included into the output?}
25 \item{se}{logical; should standard errors of the percentages be included?}
26 \item{ci}{logical; should confidence intervals of the percentages be included?}
27 \item{ci.level}{numeric; nominal coverage of confidence intervals}
28 \item{total.name}{character; name given for the total sum of counts}
29 \item{perc.label}{character; label given for the percentages if the
30 table has more than one dimensions, e.g. if \code{se} or \code{ci} is TRUE.}
31 \item{\dots}{for \code{percent.mresp}: one or several 1-0 vectors or matrices
32 otherwise, further arguments, currently ignored.}
33 }
34
35 \value{
36 A table of percentages.
37 }
38
39 \examples{
40
41 x <- rnorm(100)
42 y <- rnorm(100)
43 z <- rnorm(100)
44 f <- sample(1:3,100,replace=TRUE)
45 f <- factor(f,labels=c("a","b","c"))
46
47
48 percent(x>0)
49 percent(f)
50
51 genTable(
52 cbind(percent(x>0),
53 percent(y>0),
54 percent(z>0)) ~ f
55 )
56
57 gt <- genTable(
58 cbind("x > 0" = percent(x>0,ci=TRUE),
59 "y > 0" = percent(y>0,ci=TRUE),
60 "z > 0" = percent(z>0,ci=TRUE)) ~ f
61 )
62
63 ftable(gt,row.vars=3:2,col.vars=1)
64
65 ex.data <- expand.grid(mean=c(0,25,50),sd=c(1,10,100))[rep(1:9,rep(250,9)),]
66 ex.data <- within(ex.data,x <- rnorm(n=nrow(ex.data),mean=ex.data$mean,sd=ex.data$sd))
67 ex.data <- within(ex.data,x.grp <- cases( x < 0,
68 x >= 0 & x < 50,
69 x >= 50 & x < 100,
70 x >= 100
71 ))
72 genTable(percent(x.grp)~mean+sd,data=ex.data)
73
74 Aggregate(percent(Admit,weight=Freq)~Gender+Dept,data=UCBAdmissions)
75 }
76 \keyword{univar}