I need to drop variables from a data frame in R. My data has a column with 18 factors:
- agriculture
- fisheries ...
- unclassified
I need to remove factor #18 before creating dummy variables to say "the person X works in the Y industry". This is, I need to keep only the first 17 levels (the classified levels)
In Stata to remove the level would be
drop if rama1 == 99
(rama1 is the factor column and 99 is "unclassified")
Then to create the dummies in Stata (one binary variable per industry) I run:
quietly tabulate rama1, generate(rama1_)
that in R is:
for(i in unique(data$rama1)) {
data[paste("type", i, sep="")] <- ifelse(data$rama1 == i, 1, 0)
}
any ideas? your help is highly welcome