Description Usage Arguments Value Author(s) Examples
Simple function to compute the frequency table of a given factor according to some variables (optional). Return a data frame with the frequencies concatenate together. It is of your responsability to identify (or rename) the levels of the target variable.
1 | strFrqTable(dt, target, vars = NULL, sep_symbol = "/")
|
dt |
A data frame to process. |
target |
A string of the column name to target (i.e. the one used to compute the frequency table). |
vars |
Optional, a string or vector of strings of the column names of the variables to consider when computing the frequency table. |
sep_symbol |
Optional, the symbol to use in the concatenation of the frequencies. Default to "/". |
Return a data frame with the frequencies concatenated in a string separated by the sep_symbol argument (default to '/').
Guillaume T. Vallet gtvallet@gmail.com, University of Montreal (Canada)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Create data frame faking a group of young and elderly adults.
data = rbind(
data.frame(subject=1:10,
age=round(rnorm(10, mean=23, sd=1.5), 0),
education=round(rnorm(10, mean=15, sd=2.1), 0),
sex=sample(1:2, size=10, replace=T, prob=c(.6,.4)),
group='young'),
data.frame(subject=11:20,
age=round(rnorm(10, mean=71, sd=2), 0),
education=round(rnorm(10, mean=14, sd=1.9), 0),
sex=sample(1:2, size=10, replace=T, prob=c(.4,.6)),
group='elderly'))
# Compute the frequency table for the gender variable.
strFrqTable(data, 'sex', sep_symbol="-")
# Compute the frequency table for the gender variable by group.
strFrqTable(data, target='sex', vars='group')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.