这里是我的神学数据
year <- c(2012, 2012, 2013, 2019, 2020, 2021, 2022)
individual <- c(1, 1, 1, 2, 2, 3, 3)
group <- c("A", "B", "A", "A", "B", "A", "B")
mass <- c(84.3, 82.5, 80.6, 79.2, 82.8, 79.1, 82.6)
dataset <- data.frame(year, individual, group, mass)
I have 10 years of body mass data for individual birds across two "groups". As you ll see from the dummy dataset, I have instances where there exists mass data for one group but not the other (individual 1, year 2013). I want to only include data where I have an individual s mass for BOTH group A AND group B . I just can t figure out how to filter data this way--ideally with dplyr s filter() command.
我抱歉,如果这在一定程度上重复了另一个员额,我就能够找到一个答案,帮助我完成这一准确的过滤任务。
df2 <- dataset %>%
group_by(individual, year) %>% filter(n()>1)
^ 我利用该守则逐年逐个地整理数据,因此,它只包括一度以上的个人(个人每年只能每组一次)。 然而,从这里我看,我无法说明为何排除我随后一年中为A组或B组的个人提供第三批大规模数据但并非两者兼有的情况。 我需要一个数据集,其中仅包括一年中我拥有PBOTH集团A和B集团集体价值的个人。