I have the following (simplified) dataset:
df <- data.frame(a=c("A","A","B","B","B"),x=c(1,2,3,3,4))
df
a x
1 A 1
2 A 2
3 B 3
4 B 3
5 B 4
Since I'm working with large datasets, I use the data.table package.
Is there a way to get those lines in df, where x is minimal grouped by a. So in this case, I want to select lines 1,3 and 4.
Something like
df[,min(x),by=a]
But that doesn't give me the lines I wanna have, it just Shows me the minmum values for x grouped by a.
Any suggestions?