I am trying to split a dataframe into multiple dataframes under the criteria that the data is filtered/subsetted by a shared value of the column plot
. Previously, I used dplyr
to subset the data based on some conditions, and select the data I would like to keep (see below). Instead of copy and pasting the same code X amount of times, I want to use a for
loop to reduce the line of code.
data.p1 <- data %>%
filter(plot==1) %>%
select(posX, posY, germ_bin)
data.p2 <- data %>%
filter(plot==2) %>%
select(posX, posY, germ_bin)
After splitting the original dataframe data
into separate dataframes (e.g data.p1
), I would to apply a function such as raster
. Is it possible to also include this function in the for loop?