Reputation: 133
I have multiple data frames. In each one of them, I need to convert the 1st row into column names
My code is as follows:
cities <- objects()
library(janitor)
for (i in cities){
paste0("file_",i) <- assign(i, get(i) %>% row_to_names(row_number = 1))
}
This code creates the following error:
Error in paste0("file_", i) <- assign(i, get(i) %>% row_to_names(row_number = 1)) : target of assignment expands to non-language object
How can I fix this problem?
Upvotes: 2
Views: 61
Reputation: 886938
We can use the paste0
inside thee assign
library(dplyr)
for (i in cities){
assign(paste0("file_",i), get(i) %>% row_to_names(row_number = 1))
}
Upvotes: 1