0

I have a data frame DF of about 2000 rows with a column "Bone" that has 10 possible values (e.g., Humerus, Femur, etc.). I would like to create 10 separate data frames by splitting DF according to Bone - a data frame called Humerus that contains all of the rows from DF wherein DF$Bone contained the value "Humerus", a data frame called Femur that contains all of the rows from DF wherein DF$Bone contained the value "Femur," etc.

Code for doing this a single time: Humerus<-filter(DF, Bone == "Humerus")

How would I create a for loop (or other function) that could do this automatically rather than copying 10 lines of code and changing the variable name?

  • try [`split`](https://stat.ethz.ch/R-manual/R-devel/library/base/html/split.html): `split(DF, DF$Bone)` – bouncyball Jul 23 '18 at 16:15
  • I edited the answer at the linked duplicate to include an example that addresses your specific use case. It's at the bottom of the top answer. – joran Jul 23 '18 at 16:15
  • Thanks Joran - I tried to use the split function split(BoneFiltered,BoneFiltered$Bone) but all this did was list out the data frames separated by the $Bone value, but it didn't actually create new data frames in the work environment. – K. Lesciotto Jul 24 '18 at 13:26

0 Answers0