我试图在几列中逐行获取最大值,并使用最大值和相应的列名创建 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
我发现了这个类似的问题,但无法完成我的任务。
任何帮助是极大的赞赏。