Reputation: 61
I have a list with 14 data frames, i want to retrieve the column names of each data frame with a for loop.
files_list <- list(data_04, data_05, data_06, data_07, data_08, data_09, data_010, data_011,
data_012, data_013, data_015, data_016, data_017, data_018)
Basically i want to avoid doing this with each data frame.
colnames(data_04)
Upvotes: 1
Views: 129
Reputation: 388807
You can use lapply
and extract column names from each dataframe.
lapply(files_list, colnames)
This can also be done with purrr::map
similarly.
purrr::map(files_list, colnames)
As @Sotos suggested using names
instead of colnames
should also work for dataframes.
Upvotes: 1