Learn R Programming

memisc (version 0.11-9)

percent: Table of percentages with percentage Base

Description

percent returns a table of percentages along with the percentage base. It will be useful in conjunction with aggregate.formula.

Usage

percent(x,weights=NULL)

Arguments

x
a numeric vector or factor.
weights
a numeric vector of weights of the same length as x.

Value

  • A character vector of formatted numbers.

Examples

Run this code
ex.data <- expand.grid(mean=c(0,25,50),sd=c(1,10,100))[rep(1:9,rep(250,9)),]
  ex.data <- transform(ex.data,x=rnorm(n=nrow(ex.data),mean=ex.data$mean,sd=ex.data$sd))
  ex.data <- transform(ex.data,x.grp = cases( x < 0,
                                              x >= 0 & x < 50,
                                              x >= 50 & x < 100,
                                              x >= 100
                                            ))
  genTable(percent(x.grp)~mean+sd,data=ex.data)

  aggregate(percent(Admit,weight=Freq)~Gender+Dept,data=UCBAdmissions)

Run the code above in your browser using DataLab