【发布时间】:2021-04-05 03:05:13
【问题描述】:
这应该是一个常见问题,但我只能找到一个答案复杂的老问题here。假设我有一张航班延误表,我想根据direction 和week 等属性选择特定的delay 时间?
df<- data.frame(
Quarter = paste0("Q", rep(1:4, each = 4)),
Week = rep(c(1:8), each = 2, times = 1),
Direction = rep(c("Inbound", "Outbound"), times = 8),
Delay = c(10.8, 9.7, 15.5, 10.3, 11.8, 8.9, 5.5,
3.3, 10.6, 8.8, 6.6, 5.2, 9.1, 7.3, 5.3, 4.4)
)
上述帖子的建议答案如下所示:df[df[,"Week"]=="1" & df[,"Direction"]=="Outbound","Delay"]。有没有更好的方法来做到这一点而无需重复数据框名称,在 tidyverse 中更简单?我想一次选择一个 single 元素,比如用[[进行子集化
【问题讨论】:
标签: r