-2

I have this dataset:

library(tidyverse)
DF <- tribble(
    ~District,        ~Income,
    "District 1",        1610,
    "district2",         4906,
    "DISTRICT1",        12082,
    "DISTRICT 1",       13791,
    "district1",        21551,
    "District 2",       35126,
)

DF

And I have a list with new variable names (in real life, I have a lot of variables).

Nombres <- list(c("Distrito" , "Ingreso"))

I want to rename the dataset and my expective outcome is:

# A tibble: 6 x 2
  Distrito   Ingreso
  <chr>        <dbl>
1 District 1    1610
2 district2     4906
3 DISTRICT1    12082
4 DISTRICT 1   13791
5 district1    21551
6 District 2   35126

Thank you very much for your help. Greetings!

adircinho
  • 49
  • 4

1 Answers1

0

this is Probably a dupilicate of the question mentioned in the comments but a one line solution will be:

colnams(F) = unlist(Nombre)

and you will get:

# A tibble: 6 x 2
  Distrito   Ingreso
  <chr>        <dbl>
1 District 1    1610
2 district2     4906
3 DISTRICT1    12082
4 DISTRICT 1   13791
5 district1    21551
6 District 2   35126

do notice the not unlisting the names will give you the following:

# A tibble: 6 x 2
  'c("Distrito","Ingreso")' NA  
  <chr>                    <dbl>
1 District 1                1610
2 district2                 4906
3 DISTRICT1                 12082
4 DISTRICT 1                13791
5 district1                 21551
6 District 2                35126
David
  • 8,113
  • 2
  • 17
  • 36