I am trying to create a list of factors that have a binary response and have been using cast.
DF2 <- cast(data.frame(DM), id ~ region) names(DF2)[-1] <
Here's sort of a "tricky" way to do it in one line using table (the brackets are important). Assuming your data.frame is named df:
table
data.frame
df
(table(df) > 0)+0 # region # id 1 2 3 # 1 0 1 1 # 2 0 1 0 # 3 1 0 0
table(df) > 0 gives us TRUE and FALSE; adding +0 converts the TRUE and FALSE to numbers.
table(df) > 0
TRUE
FALSE
+0