I want to combine all factors with a count less than n into one factor named \"Else\"
For example if n = 3 then in the following df I want to combine \"c\", \"d\" and \"
Why not something like this?
library(data.table) dt <- data.table(df) dt[,ynew := ifelse(.N < 3, "else",as.character(y)), by = "y"]