0

データフレームの各行の最小時間を取得しようとしています。選択する列の名前はわかりませんが、最初から 5 番目の列になることはわかっています。

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 でグループ化も試みましたが、これは違いはありません

4

1 に答える 1