1

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?

Chris Snow
  • 22,050
  • 31
  • 128
  • 279

1 Answers1

4

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

Chris Snow
  • 22,050
  • 31
  • 128
  • 279