This should be a common question, but I was only able find an old question with a complicated answer here. Say I have a table for flight delays and I want to select specific delay
time based on attributes like direction
and week
?
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)
)
A proposed answer of the above post look like this:df[df[,"Week"]=="1" & df[,"Direction"]=="Outbound","Delay"]
. Is there a better way to do this without repeating data frame name, something simpler in tidyverse? I want to select a single element at a time, something like subsetting with [[