I have a very wide dataframe with where each column exists three times with varying suffixes: xxx_A1.5, xxx_A2.0, xxx_A2.5. Consider this example:
df1 <- data.frame(col1_A1.5 = c(1,2,3,4),
col1_A2.0 = c(2,3,4,5),
col1_A2.5 = c(3,4,5,6),
col2_A1.5 = c(10,20,30,40),
col2_A2.0 = c(20,30,40,50),
col2_A2.5 = c(30,40,50,60))
I now want to combine all col1_xxx into one column (named col1; same for col2 etc.) according to this pattern: col1_A2.0 [colA1.5, colA2.5]. The desired result in the example is thus:
col1 col2
1 "2 [1, 3]" "20 [10, 30]"
2 "3 [2, 4]" "30 [20, 40]"
3 "4 [3, 5]" "40 [30, 50]"
4 "5 [4, 6]" "50 [40, 60]"
Since I have > 100 columns, I need a pattern-based solution; I've tried several combinations of mutate and across but cannot achieve the desired result. Can someone offer a hint or solution?
Thanks in advance.