我正在寻找每行列的最小值(或最大值)的解决方案。喜欢:
# my data.frame is df:
library(tibble)
df <- tribble(
~name, ~type_1, ~type_2, ~type_3,
"a", 1, 5, 2,
"b", 2, 2, 6,
"c", 3, 8, 2
)
# and output should be result_df:
result_df <- tribble(
~name, ~type_1, ~type_2, ~type_3, ~min_val, ~min_col,
"a", 1, 5, 2, 1, "type_1",
"b", 8, 2, 6, 2, "type_2",
"c", 3, 8, 0, 0 ,"type_3"
)
I tried rowwise
and pmax
功能但没有起作用。我可以使用收集和分组,但我想知道是否存在按列/按行的解决方案。
这种方法对于均值、中值函数也很有用。
感谢您的帮助。