【发布时间】:2020-10-21 14:19:49
【问题描述】:
我正在尝试在多列中逐行获取最大值,并使用最大值和相应的列名创建 2 个新列。 然后,使用列名,我需要选择共享该列名的子字符串的另一列的值。
这是我试图解决的一个例子:
measure_day1 <- c(1,2,5)
measure_day2 <- c(5,7,1)
measure_day3 <- c(2,3,9)
temp_day1 <- c(25, 27, 29)
temp_day2 <- c(31, 33, 35)
temp_day3 <- c(14, 16, 19)
df <- data.frame(measure_day1, measure_day2, measure_day3, temp_day1, temp_day2, temp_day3)
measure_day1 measure_day2 measure_day3 temp_day1 temp_day2 temp_day3
1 1 5 2 25 31 14
2 2 7 3 27 33 16
3 5 1 9 29 35 19
这将是结果:
measure_day1 measure_day2 measure_day3 temp_day1 temp_day2 temp_day3 measure_max day_measure_max temp_day_measure_max
1 1 5 2 25 31 14 5 measure_day2 31
2 2 7 3 27 33 16 7 measure_day2 33
3 5 1 9 29 35 19 9 measure_day3 19
我发现了这个类似的问题,但无法完成我的任务。
For each row return the column name of the largest value
非常感谢任何帮助。
【问题讨论】:
标签: r dataframe substring rowwise