I have 7 variables in the datasets .out of which one variable has 5 levels ,I need create 5 datasets for the same.
Asked
Active
Viewed 19 times
-1
-
Please consider to give a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – markus Nov 19 '18 at 20:29
1 Answers
0
We can use split
to create a list
of data.frame
s in a list
. If the variable name of the column with 5 levels is 'Col', use that to split
the dataset
lst <- split(data, data$Col)
It is better not to create multiple objects in the global environment.

akrun
- 874,273
- 37
- 540
- 662
-
@PraveenChougale Assuming that you have a column with 5 unique values, it would split as intended – akrun Nov 19 '18 at 20:38
-
-
1@PraveenChougale You can do all the manipulations within the `list`. If you need to save it, `lapply(names(lst), function(x) write.csv(lst[[x]], paste0(x, ".csv")))` – akrun Nov 19 '18 at 20:43