I have a data frame with multiple columns, a small version of the data frame looks like this:
wind<- c(0.84, 1.77, 3.5, 6.44, 7.55)
ROS<- c(0.01,0.03,0.05, 0.07, 0.1)
T_0.1_1 <- c(1110, 350, 250, 300, 311)
T_0.2_1 <- c(560, 200, 364, 258, 159)
T_0.3_1 <- c(258, 147, 369, 123, 624)
T_180.1_1 <- c(554, 226, 547, 842, 366)
T_180.2_1 <- c(258, 147, 369, 123, 624)
T_180.3_1 <- c(110, 350, 250, 300, 311)
df<-data.frame(wind,ROS,T_0.1_1,T_0.2_1,T_0.3_1,
T_180.1_1,T_180.2_1, T_180.3_1)
I want to create another data frame with the variables "wind" and "ROS" and for each wind-ROS I want to select the variable that start with T_0. and T_180 with the max value and create a new variable with the name of the variable. The new data frame should look like this one:
wind<- c(0.84, 1.77, 3.5, 6.44, 7.55)
ROS<- c(0.01,0.03,0.05, 0.07, 0.1)
new_T0<- c('T_0.1_1', 'T_0.1_1', 'T_0.3_1', 'T_0.1_1', 'T_0.3_1')
new_T180<- c('T_180.1_1', 'T_180.3_1', 'T_180.1_1', 'T_180.1_1', 'T_180.2_1')
df_new<-data.frame(ROS, wind,new_T0, new_T180)
Any help how I can do that is very much appreciated! Thank you!