0

I have a large dataframe that has all of the data for the project I am working on and I am trying to produce a series of smaller dataframes that contain data that match for two columns. So for example for the example data below, I need to write a piece of script that produces a series of data frames for datapoints where year and colony are the same (e.g. year = 2012, colony = A; year = 2012, colony = B).

year <- c(2012, 2012, 2012, 2012, 2013, 2013, 2013, 2013, 2014, 2014, 2014, 2014)
colony <- c ('A', 'A', 'B', 'B', 'A', 'A', 'B', 'B', 'A', 'A', 'B', 'B')
measurement <- c(4,6,1,4,8,2,1,5,4,1,3,8)
data <- data.frame(year, colony, measurement) 

At the moment the best I can do is producing each individually:

A2012 <- filter(data, colony == 'A' & year == 2012)
B2012 <- filter(data, colony == 'B' & year == 2013)

etc. However, there are about 80 dataframes to produce so it would be better to automate this if possible. Does anyone know a way that I could do this quicker?

unknown
  • 813
  • 8
  • 19

0 Answers0