Skip to content

filter DT using max() in i: group_id==max(group_id) #858

@jangorecki

Description

@jangorecki

Use case to pick only observations related to last group
Take following dt:

dt <- data.table(group_id = c(1,1,1,2,2,2,3,3,3), val = rnorm(9))

This works in 1.9.3 but doesn't work in 1.9.4:

dt[group_id == max(group_id)]

As for now to achieve the following in 1.9.4 I need to do:

dt[group_id == max(dt$group_id)]
# or
dt[,.SD][,max_group_id:=max(group_id)][group_id == max_group_id][,max_group_id:=NULL][]
# [,.SD] - prevent write dt by reference

Is there any recommended (in terms of future support) way of achieve that?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions