0

In relation to another post, I would like to split data frames stored in a list into multiple data frames individually.

Here is scripts that I am using now.

library(dplyr)

    iris %>% mutate(Sepal=rowSums(select(.,starts_with("Sepal"))),
                    Length=rowSums(select(.,ends_with("Length"))),
                    Width=rowSums(select(.,ends_with("Width"))))
iris2 <- iris
iris3 <- iris

iris.set <- list(iris,iris2,iris3)

iris.map <- map(iris.set, ~ .x %>% mutate(Sepal=rowSums(select(.,starts_with("Sepal"))), Length=rowSums(select(.,ends_with("Length"))), Width=rowSums(select(.,ends_with("Width")))))

iris <- iris.map[1]
iris2 <- iris.map[2]
iris3 <- iris.map[3]

However I prefer much programmatic approach to split resulted list iris.map into multiple data frames individually.

Related post How to apply same operation to multiple data frames in dplyr-R?

HSJ
  • 687
  • 6
  • 16
  • 3
    Why do you want this? It's much, much easier in R to work with a list a data.frame rather than a bunch of similarly named variables. The latter often leads to `get()` and `assign()` which are just a headache. Just leave them in a list. (But if you really **have** to separate them, look at `list2env()` -- that would be the easiest way) – MrFlick Jun 14 '18 at 14:45
  • Thank you. I have multiple original data frames and need to apply the same operation to them then back them into separate data frames again. As I am using `map` function for the former purpose, somehow I need to do the latter operation. I will check original post. – HSJ Jun 14 '18 at 15:03
  • It still sounds like it would be way easier if you just kept them all in a list in all parts of your analysis. – MrFlick Jun 14 '18 at 15:04
  • That is your point. It is simply because I am not familiar with operating lists and I do not want to change current scripts not to make unanticipated errors. – HSJ Jun 14 '18 at 15:10

0 Answers0