0

I have a very large data frame and want to create some simple tables. The problem with a dataset so big, is that I have a lot of values that only occur a few times.

What I want to achieve is to create a table for each of the qualitative variables, and have the least occuring values in each variable appear under a grouped tag. The first part is easy enough:

 sapply(dat[!sapply(dat, is.numeric)], table)

but how do I group the values that are present less than x times and also put them in the table in a 'Others' tag? Is there any table function that has a parameter that does this? Or am I going to have to manually manipulate the data.frame, find all the lest occuring values and change the value for them to 'Other'?

Dorian
  • 3
  • 3
  • You're going to need to provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for this, as it is too vague at the moment. Whether you use a portion of your actual data or a standard data as an example is up to you, but please find something and edit your question. – r2evans Feb 28 '17 at 00:30
  • See `fct_lump` from the `forcats` package. It automates grouping infrequent categories into a single "other" group. – eipi10 Feb 28 '17 at 00:34
  • That was exactly what i was looking for eipi10. Thanks – Dorian Feb 28 '17 at 02:44

0 Answers0