I would like to apply the same operation to multiple data frames in \'R\' but cannot get how to deal with this matter.
This is an example of pipe
operat
If you turn your operation into a function:
library(dplyr)
my_fun <- function(x) {
x %>%
mutate(Sepal=rowSums(select(.,starts_with("Sepal"))),
Length=rowSums(select(.,ends_with("Length"))),
Width=rowSums(select(.,ends_with("Width"))))
}
You can pipe a list of data frames to it easily:
result <- list( iris, iris2, iris3 ) %>%
lapply( my_fun )