freq {R3port}R Documentation

Calculate frequency statistics on data frame

Description

This function calculates frequency statistics on a data frame. It is intended to use to calculate the frequency and percentages based on a predefined denominator.

Usage

freq(
  dfrm,
  vars,
  id,
  denom = nrow(dfrm),
  dig = 2,
  total = NULL,
  totaldenom = nrow(dfrm),
  spacechar = NULL
)

Arguments

dfrm

data frame to calculate the statistics on

vars

character vector of variable(s) within the data frame to perform the statistics on

id

character vector of variable(s). In case id is set the function will take into account non duplicated values for id in the calculations.

denom

the denominator for the calculation of percentage. See details for valid options

dig

number of digits to use for output percentage (frequency is displayed as integer)

total

vector of variable(s) within the data frame to calculate totals on

totaldenom

the denominator for the calculation of percentage of the totals. See details for valid arguments

spacechar

the character to use for space for combined frequency and percentage in output (e.g. "~" for tex documents)

Details

The function calculates frequency statistics of variable(s) within a data frame. Furthermore, the frequencies for a total can also be generated. To calculate the percentages, the denominator should be supplied (and in case totals has a value also totaldenom). The denom and totaldenom can be a constant numerical value, a variable within the data frame or a separate data frame. In case the argument is a data frame, the function will attempt to merge this data frame based on equal variables within dfrm/denom and dfrm/totaldenom. The possibility for a separate denominator is implemented as in many cases the denominator is not the total number of observations but is defined elsewhere (e.g. for number of adverse events, the total number of subjects is used as denominator).

Value

The function returns a dataframe with frequencies and percentages

Examples


data(Indometh)
freq(Indometh,vars="time",id="Subject",
        denom=nrow(Indometh),total="",totaldenom=nrow(Indometh))

[Package R3port version 0.2.5 Index]