我正在尝试获取数据框中每一行的最短时间。我不知道我将选择的列的名称,但我知道它们将是第一列到第五列:
data <- structure(list(Sch1 = c(99, 1903, 367),
Sch2 = c(292,248, 446),
Sch3 = c(252, 267, 465),
Sch4 = c(859, 146,360),
Sch5 = c(360, 36, 243),
Student.ID = c("Ben", "Bob", "Ali")),
.Names = c("Sch1", "Sch2", "Sch3", "Sch4", "Sch5", "Student.ID"), row.names = c(NA, 3L), class = "data.frame")
# this gets overall min for ALL rows
data %>% rowwise() %>% mutate(min_time = min(.[[1]], .[[2]], .[[3]], .[[4]], .[[5]]))
# this gets the min for EACH row
data %>% rowwise() %>% mutate(min_time = min(Sch1, Sch2, Sch3, Sch4, Sch5))
.[[1]]
在按行模式下,列表示法是否应该返回所有值?我也尝试过在 Student.ID 上分组而不是按行分组,但这没有任何区别