I've been trying to search for a way to write a for loop to create subsets from my dataset, based on the variable plot number (plot_no).
I could do in manually like this. However, there are 30 plots so I rather write a for loop.
l_plot1 <- light[light$Plot_No == 1,] l_plot2 <- light[light$Plot_No == 2,] l_plot3 <- light[light$Plot_No == 3,]
I have tried this:
all_plots <- unique(light$Plot_No)
n <- length(all_plots)
for(i in 1:n){plot_i <- all_plots[i]
plot_i <- light[light$Plot_No == i,]
}
But then the for loop keeps overwriting the data frame and I end up with only a data frame of the last plot.
How do I write it so that all 30 dataframes will save and are filled with data from the light data frame?