我有一些如下数据
plot Tsoil_11 Tsoil_12 Tsoil_13 Tsoil_21 Tsoil_22 SWC_11 SWC_12 SWC_13 SWC_21 SWC_22
11 1 2 3 4 5 6 7 8 9 10
11b 11 12 13 14 15 16 17 18 19 20
11c 21 22 23 24 25 26 27 28 29 30
12 31 32 33 34 35 36 37 38 39 40
13 41 42 43 44 45 46 47 48 49 50
21 51 52 53 54 55 56 57 58 59 60
21b 61 62 63 64 65 66 67 68 69 70
22 71 72 73 74 75 76 77 78 79 80
...
我想添加Tsoil和SWC的两列。理想的数据应如下所示,
plot Tsoil SWC
11 1 6
11b 11 16
11c 21 26
12 32 12
13 43 48
21 54 59
21b 64 69
22 75 80
...
如何在R中实现?
We can use
pivot_longer
and specify thenames_sep
as_
, thenfilter
values based on the 'ind' column comparison (suffix of column names) with the number only values from 'plot'数据