Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何仅返回满足 R 中年龄标准的高度?
IE
Age Height 1 0.5 1 0.6 1 0.7 1 0.6 4 2.0 4 2.3 4 2.3
我只想要与 Age == 4 相对应的高度。R 中的哪个函数允许我这样做?
试试这个:
dat <- data.frame(Age=c(1,1,1,1,4,4,4),Height=c(0.5,0.6,0.7,0.6,2.0,2.3,2.3)) dat[dat$Age==4,2]
此外,由于您在问题标题中使用了“子集”,因此您可以使用该命令。看看?subset,你会发现它subset(dat, Age == 4, select = "Height")也有效。
?subset
subset(dat, Age == 4, select = "Height")