pct: Add Percentage Columns to a Dataframe

Description Usage Arguments Value Examples

View source: R/convert.R

Description

This function will add extra columns to an existing dataframe. The second argument 'clmn' should specify which column(s) of the dataframe the percentage should be calculated by dividing each column's row-element by it's sum.

Usage

1
pct(df, clmns)

Arguments

df

A dataframe with numeric columns.

clmns

the names of the columns for which the percentage column should be calculated from.

Value

The original dataframe plus extra percentage columns corresponding to original columns in the dataframe.

Examples

1
2
df <- data.frame(a=c(1,2,3), b=c('x','y','z'), c=c(5,3,2))
pct(df, c('a','c'))

caroline documentation built on May 29, 2017, 12:09 p.m.

Related to pct in caroline...