-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!

1
  • 3
    Did you happen to see this? Commented May 9, 2019 at 18:26

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.