I have a data frame that I have read from disk and then applied a filter:
df <- df[ df$x > 10, ]
Question: How can I refactor all factors in the data frame now that several rows have been removed?
I have a data frame that I have read from disk and then applied a filter:
df <- df[ df$x > 10, ]
Question: How can I refactor all factors in the data frame now that several rows have been removed?
The following worked for me:
df <- as.data.frame(lapply(df, function (x) if (is.factor(x)) factor(x) else x))
Source: http://r.789695.n4.nabble.com/Refactor-all-factors-in-a-data-frame-tp826749p826754.html