小编And*_*ano的帖子

Filter rows within data.table group if max group value > some value

I am trying to filter all rows within a group in a data.table if a max value within that group is > some value. Below is how I would do it in DPLY and how I got it working in two steps in data.table.

#DPLYR 
df<-data.table(
  x =1:12
  ,y = 1:3
)

df %>% group_by(y) %>% 
  filter(max(x) < 11)

##data.table
df[,max_value :=max(x),by=y][max_value<11]

The output should be

    x y
1:  1 1 
2:  4 1 
3:  7 1 
4: 10 1 …
Run Code Online (Sandbox Code Playgroud)

r data.table

6
推荐指数
1
解决办法
61
查看次数

标签 统计

data.table ×1

r ×1