Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

renaming column names with dplyr using tidyselect functions

$
0
0

I am trying to rename a few columns using dplyr::rename and tidyselect helpers to do so using some patterns.

How can I get this to work?

library(tidyverse)

# tidy output from broom (using development version)
(df <- broom::tidy(stats::oneway.test(formula = wt ~ cyl, data = mtcars)))

#> # A tibble: 1 x 5
#>   num.df den.df statistic   p.value method                                      
#>    <dbl>  <dbl>     <dbl>     <dbl> <chr>                                       
#> 1      2   19.0      20.2 0.0000196 One-way analysis of means (not assuming equ~

# renaming
df %>% 
  dplyr::rename(
  .data = .,
  parameter1 = dplyr::matches("^num"),
  parameter2 = dplyr::matches("^denom")
  )
#> Error: Column positions must be scalar

Created on 2020-01-12 by the reprex package (v0.3.0.9001)


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>