In R I have several dataframes with unique names. These names are also available in a column named as names. I need to run a loop like this
for(i in 1:length(names)) {
}
in which I will select the dataframes and do following things
- rename the first column to series
- remove NAs from series
filter(!is.na(series
))
- use the following command to name the similar names unique
group_by(series
) %>%
mutate(series1
= if(n( ) > 1) {paste0(series
, row_number( ))}
else {paste0(series
)}) %>% ungroup(series)
- then use gather command to convert columns into rows and some rows into columns 5 and add a column in the dataframe which has repeated values of unique dataframe name with header label.
The problem is that my try like following in a loop is not working
colnames(names[i])[1] <- "series"