在一项实验中,我试图找到第一胎出生的时间。有四只动物,按照id和rep给出(A1、A2、B1、B2),它们的年龄和幼崽。对于每个id和rep,我只想保留第一胎出生的行。
id <- c("A","A","A","A","A","A","B","B","B","B","B","B","B","B","B")
rep <- c(1,1,1,2,2,2,1,1,1,1,2,2,2,2,2)
age <- c(0,1,2,0,1,2,0,1,2,3,0,1,2,3,4)
babies <- c(0,0,1,0,1,0,0,0,0,1,0,0,0,1,1)
df <- data.frame(id,rep,age,babies)
所以在这里,最终的数据框应该是这样的
id <- c("A","A","B","B")
rep <- c(1,2,1,2)
age <- c(2,1,3,3)
babies <- c(1,1,1,1)
df <- data.frame(id,rep,age,babies)