by_g <- (df, A)
df.new <- by_g %>%
summarise(v <- max(C))%>% arrange(A)
当Column-C具有最大计数并按列A分组时,我无法获得B列内容
答案 0 :(得分:1)
按“A”分组后,我们可以使用which.max
中的slice
来获取与“C”中的max
值对应的行
df %>%
group_by(A) %>%
slice(which.max(C))
df <- structure(list(A = c("B001", "B001", "B001", "B001", "B002",
"B002", "B002", "B003", "B003", "B003", "B003", "B003", "B003"
), B = c("", "Elec VoltageAsymmetry", "Pitch LubricationStop",
"Pitch SafetyTestActiv", "", "Elec VoltageAsymmetry", "Pitch LubricationStop",
"", "Elec CurrentAsymmetry", "Elec VectorSurgeStop", "Elec VoltageAsymmetry",
"Pitch FreqConvPitch2 ErrStop", "Pitch LubricationStop"), C = c(1,
1, 5, 1, 1, 1, 5, 1, 2, 2, 2, 1, 4)), .Names = c("A", "B", "C"
), row.names = c(NA, -13L), class = "data.frame")