I have a data frame that looks like this:
CEMETERY CONTEXT SEX BONE MEASUREMENT VALUE
1 Medieval-St. Mary Graces 6225 MALE HuE1 L 64.1
2 Medieval-St. Mary Graces 6225 MALE HuE1 R 62.7
3 Medieval-St. Mary Graces 6225 MALE HuHD L 50.1
4 Medieval-St. Mary Graces 6225 MALE HuHD R 51.3
5 Medieval-St. Mary Graces 6225 MALE HuL1 R 346.0
6 Medieval-St. Mary Graces 6272 FEMALE HuHD L 41.3
I need to remove any specimens (CONTEXTs) where there is only a bone measurement for left (L) or (R), instead of having both (e.g. if a specimen has HuE1L but not HuE1R then I need to remove it). I'm not sure what the best way to do this is as the data frame is too large to individually remove certain rows. To create this data frame I used the merge() function so I also have data frames for each bone (left and right are in separate data frames), if that makes any difference to what I need to do?
EDIT: I tried using data.table:
library(data.table)
setDT(df)
setkey(df, CONTEXT, BONE)
df[df[, .N, key(df)][N == 2, .(CONTEXT, BONE)]]
but that returns this:
CEMETERY CONTEXT SEX EXPANSION VALUE
1: Medieval-Spital Square 19 FEMALE HuE1 L 57.9
2: Medieval-Spital Square 19 FEMALE HuE1 R 58.8
3: Medieval-Spital Square 19 FEMALE HuHD R 44.6
4: Medieval-Spital Square 19 FEMALE HuL1 L 326.0
5: Medieval-Spital Square 19 FEMALE HuL1 R 332.0
474: Medieval-St. Mary Graces 16332 MALE RaHD L 25.4
475: Medieval-St. Mary Graces 16344 MALE HuHD R 48.8
476: Medieval-St. Mary Graces 20001 FEMALE HuHD L 40.2
477: Medieval-St. Mary Graces 20001 FEMALE HuHD R 39.8
478: Medieval-St. Mary Graces 20001 FEMALE RaHD R 20.8
so it hasn't actually removed bone measurements that only have left or right. To clarify - the Ls and Rs are part of the column 'EXPANSION', not a separate column - would I first need to make that a column on its own/how would I go about doing this?