All*_*ron 7

Use the keyword '.value' in the names_to argument to keep that part of the column name in wide format:

tidyr::pivot_longer(df, c(-ID, -`background vars`),
                    names_sep = '\\.', 
                    names_to = c('.value', 'recurrence'))
#> # A tibble: 6 x 5
#>      ID `background vars` recurrence  var1  var2
#>   <int> <chr>             <chr>      <int> <int>
#> 1     1 data1             A              1     2
#> 2     1 data1             B              3     4
#> 3     1 data1             C              5     6
#> 4     2 data2             A              7     8
#> 5     2 data2             B              9    10
#> 6     2 data2             C             11     1

更多推荐

变量