lapply
Access and preserve list names in lapply function
I believe that lapply by default keeps the names attribute of whatever you are iterating over. When you store the names of myList in n, that vector no longer has any “names”. So if you add that back in via, names(n) <- names(myList) and the use lapply as before, you should get the desired result. … Read more
Read all files in a folder and apply a function to each data frame
On the contrary, I do think working with list makes it easy to automate such things. Here is one solution (I stored your four dataframes in folder temp/). filenames <- list.files(“temp”, pattern=”*.csv”, full.names=TRUE) ldf <- lapply(filenames, read.csv) res <- lapply(ldf, summary) names(res) <- substr(filenames, 6, 30) It is important to store the full path for … Read more
passing several arguments to FUN of lapply (and others *apply)
If you look up the help page, one of the arguments to lapply is the mysterious …. When we look at the Arguments section of the help page, we find the following line: …: optional arguments to ‘FUN’. So all you have to do is include your other argument in the lapply call as an … Read more