I am a fisheries stock assessment scientist and am currently struggling with this issue.
Basically, I want to create a new dataframe with a subset of the data from each fish stock that I am looking at. Ideally, I would like to do this with a for loop (or if there is a function that does this built into r or a package that would also be great).
The pseudo-code for this issue would be
FOR EACH fishStock IN dataFrame
CREATE NEW DATAFRAME CALLED fishStock
DATAFRAME(fishStock) = SUBSET OF dataFrame WHERE fishStock = fishStock
Once this process is completed, I should have a data frame for each fish stock listed in my original data frame that contains a subset of all the data for that stock.
Without a for loop, I would have to write out a line of code for each stock that would be long and look like this:
stock1<-subset(data,FishStock =="stock1")
stock2<-subset(data,FishStock =="stock2")
stock3<-subset(data,FishStock =="stock4")
Hopefully what I am trying to get across makes sense.