1

If I have a list of dfs in my environment, and I would like to rename them base on a mapping file I created, how can I do that?

my mapping file is looks like this:

mapping<- structure(list(Tab = c("Study", "Score", "Level", "Level2", 
"Level3", "level_Grouped"), DatasetName = c("Output3", "Output4", 
"Output5", "Output6", "Output7", "Output3.g")), row.names = c(NA, 
-6L), class = c("tbl_df", "tbl", "data.frame"))

I am thinking to get the output in the list first, then loop through the rename process. but I kind of lost in the process. what should I use for rename a df? Could anyone guide me on this?

output_list<-ls(pattern="^Output")
lapply(output_list, function(x)...)

Thanks.

Stataq
  • 1,833
  • 3
  • 11
  • 1
    Almost always, the answer to this is "if you have a list of data frames, then you should put them in an actual list object". This stops you having to do ugly and dangerous things with `get()` and `assign()`. You just do `names(my_list_of_dfs) – dash2 Nov 07 '21 at 18:21

1 Answers1

1

I don't think this is possible because you cannot rename data.frame in R. More info here: How can I change the name of a data frame

Dave4048
  • 152
  • 8