Automatically expanding an R factor into a collection of 1/0 indicator variables for every factor level

Use the model.matrix function:

model.matrix( ~ Species - 1, data=iris )

Leave a Comment