1

Currently I have two lists in R, the first list has 20 data frames, each with 25 columns. The second list is 20 sets of 25 characters, i.e. column names. What I want to do is have the column names in the first data frame equal to the values in the first set of characters in the second list, etc.

Any insight is much appreciated!!

lwhite3
  • 27
  • 5
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. It doesn't have to be your exact data, just a representative example. – MrFlick Feb 07 '20 at 19:15

1 Answers1

1

We can use Map from base R. As the lists are of the same length, can use Map to change the column names of the first with the vector values in second list assuming that the column names to be changed are in the same order

lst1N <- Map(setNames, lst1, lst2)
akrun
  • 874,273
  • 37
  • 540
  • 662