In R how to use a for loop to create a series of data frame? Just for illustration purpose, if need to keep all setosa species of iris data frame to df_setosa, all versicolor in df_versicolor, how to do so?
Asked
Active
Viewed 66 times
-1
-
2Possible duplicate of [Split a large dataframe into a list of data frames based on common value in column](http://stackoverflow.com/questions/18527051/split-a-large-dataframe-into-a-list-of-data-frames-based-on-common-value-in-colu) – Ronak Shah Apr 01 '17 at 09:29
-
Why would you want to do so? If you have data of the same structure it's almost always better to keep the data in one data frame. – Uwe Apr 02 '17 at 19:26
1 Answers
0
You could use split
which will will give you a list with your dataframes.

FlorianGD
- 2,336
- 1
- 15
- 32
-
Thank you. i could only come up with a simple example, actually what i want to do is to pass each category into a series of operations then output as a data frame of that category. in that case, split won't be enough, how can I output multiple data frame via for loop? – santoku Apr 01 '17 at 14:47
-
@santoku Do you want to apply similar operations on each chunk? Appears to me as a use case for `lapply()` and/or grouping using `data.table` or `dplyr`. – Uwe Apr 02 '17 at 19:34