convert.bin.fac: Take a data.frame and convert any columns consisting of only...

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Take a data.frame and convert any columns consisting of only 0's and 1's (binary) values, to a factor variable, to ease calculation and interpreations of subsequent analysis.

Usage

1
convert.bin.fac(x, ignore.missing = FALSE)

Arguments

x

a data frame of patient characteristics from a study.

ignore.missing

a scalar logical indicating on how to deal with missing data. When true, the function will convert any column with 0's/1's/NA's into a factor, when false (default), NA's will prevent conversion.

Details

This function convert any columns consisting of only 0's and 1's (binary) values, to a factor variable, to ease calculation and interpreations of subsequent analysis.

Value

the same data.frame with updated columns

Author(s)

Jesse D. Raffa

See Also

kable xtable CreateTableOne

Examples

1
2
3
4
5
6
7
8
set.seed(1)
N <- 100;
dataf <- data.frame(age=c(runif(N-1,0,100),NA),sex=sample(c(0,1,NA),N,replace=TRUE),cholesterol=rnorm(N,100,30))
summary(dataf)
out <-  convert.bin.fac(dataf)
summary(out)
out <- convert.bin.fac(dataf,ignore.missing=TRUE)
summary(out)

jraffa/MIMICbook documentation built on May 19, 2019, 11:51 p.m.