I am trying to apply same functions to several data frames. My data looks like this. I have several data frames for different years. I want to get rid of year specific names in order to merge data frames into one.
ID | educ_1995 | year_1995 |
---|---|---|
k1 | 0 | 1995 |
k2 | 1 | 1995 |
k3 | 0 | 1995 |
I have tried following:
files <- list(workers_1995, workers_1996)
files <- lapply(files, function)
# I tried to make a list of my data frames and then write a function for them.
myfunc <- function(files){
files %>%
rename(igang=starts_with("igang")) %>%
rename(year=starts_with("year"))
}
I would like to get the results in form of same tibbles, but with changed names.
Change the order and place myfunc
inside the parentheses:
files <- list(workers_1995, workers_1996)
myfunc <- function(onefile){
onefile %>%
rename(igang=starts_with("igang")) %>%
rename(year=starts_with("year"))
}
lapply(files, myfunc)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.