Skip to content
Prev 106724 / 398506 Next

coded to categorical variables in a large dataset

sj wrote:
Here is one way you might do it:

X <- sample(1:5, 100, replace=TRUE)

# Your 5 event variables in a matrix
model.matrix(lm(rnorm(length(X)) ~ as.factor(X) - 1))

  Also, along the lines of your approach below, the following using
ifelse() might be better:

event3 <- ifelse(test2 == 3, 1, 0)

  I'm sure other people will post different solutions probably more
elegant than these.