Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

bag

Multi-indicators / "Bag o Words"


Description

This creates an indicator matrix from several columns.

Usage

bag(..., prefix = ".", levels = NULL)

Arguments

...

the columns to bag

prefix

a prefix for the column names

levels

levels shared among all columns

Value

a n*p indicator matrix

Author(s)

References

Examples

df2 <- structure(list(Dx1 = c("231", "231", "001", "245", "231", "001", 
"231", "001", "231", "001", "001", "245", "001", "231", "245", 
"245", "001", "231", "245", "001"), Dx2 = c("001", "001", "001", 
"001", "001", "001", "001", "234", "001", "234", "001", "001", 
"001", "001", "001", "777", "777", "234", "001", "234"), Dx3 = c("456", 
"001", "444", "444", "001", "001", "444", "001", "001", "001", 
"444", "001", "444", "456", "456", "444", "444", "456", "001", 
"456")), class = "data.frame", row.names = c(NA, -20L))

Y <- 1:nrow(df2)
m <- lm(Y~bag(Dx1, Dx2, Dx3), df2)
summary(m)

stackoverflow

Stack Overflow's Greatest Hits

v0.7.0
CC BY-SA 4.0
Authors
Neal Fultz <nfultz@gmail.com> and the StackOverflow.com community
Initial release
2020-01-03

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.