D. Chamberlin D. Chamberlin - 1 year ago 63
R Question

How Can I make Multiple Subsets Based On A Column

I am working with a very large data set and I need to make multiple subsets from the data set without having to individually code for each subset. I want to create subsets for each Boat name in the first column.

I know how to do this boat by boat but I would like to make multiple subsets at once. I included a small sample of the data frame I am working with.

I would like to have 3 subsets from this sample data, one for each the Dawn Marie, Kraig K, and Lake Lady. Thanks for the help.

Boat Net Targeted Species Yellow Perch
Dawn Marie 37 Yellow Perch 500
Kraig K 35 Yellow Perch 400
Dawn Marie 36 Yellow Perch 1100
Dawn Marie 34 Yellow Perch 2000
Lake Lady 30 Yellow Perch 900
Dawn Marie 31 Yellow Perch 1200
Kraig K 33 Yellow Perch 1600
Dawn Marie 44 Yellow Perch 400
Lake Lady 42 Yellow Perch 800
Dawn Marie 40 Yellow Perch 500
Dawn Marie 38 Yellow Perch 600
Lake Lady 39 Yellow Perch 400

Answer Source

Try the split function.


split divides the data in the vector x into the groups defined by f. The replacement forms replace values corresponding to such a division. unsplit reverses the effect of split.


 split(x, f, drop = FALSE, ...)


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download