0

I have dataset with the 3 columns.

price
Factor (numeric var 1-15 categories)
group (string (100 categories))

I need for each Factor categories select only these groups who have observation more then five! How do it?

This is not correct!

new<-city[(city$group)>5,]
Pierre Lapointe
  • 16,017
  • 2
  • 43
  • 56
H.Siw
  • 15
  • 5

1 Answers1

3

We can do this with data.table. Convert the 'data.frame' to 'data.table', grouped by 'Factor', 'group', get the Subset of Data.table (.SD) where the number of rows is greater than 5 (.N >5)

library(data.table)
setDT(city)[, .SD[.N >5], by = .(Factor, group)]
akrun
  • 874,273
  • 37
  • 540
  • 662