Closed
Description
I want to select all columns M1, F1, M2 & F2. If I specify this using a single use of num_range()
it unexpectedly selects just two columns. Instead I would expect four. I show the expected result using starts_with()
but of course I'd prefer num_range
as I can be explicit about the numbering too.
library(tidyverse);
library(magrittr);
#>
#> Attaching package: 'magrittr'
#> The following object is masked from 'package:purrr':
#>
#> set_names
#> The following object is masked from 'package:tidyr':
#>
#> extract
df <- data.frame(M1=1, F1=3, M2 = 5, F2 = 0);
df %>% select(num_range(c("M", "F"), 1:2));
#> M1 F2
#> 1 1 0
df %>% select(starts_with(c("M", "F")))
#> M1 M2 F1 F2
#> 1 1 5 3 0
Created on 2024-05-29 with reprex v2.1.0
Metadata
Metadata
Assignees
Labels
No labels