I have a very long data frame with different plots, dates of sampling and values.
An example of the data frame is below.
How could I calculate sums of column “value” for plot A and for plot B if the end dates are different?
For examples for plot A end date is 5.1.2010 and the sum would be 25 and for plot B is 3.1.2010 so the sum would be 12.
I hope the question is understandable?
Data frame look like this:
date <- c("1.1.10", "1.1.10", "2.1.10", "2.1.10", "3.1.10", "3.1.10", "4.1.10", "4.1.10", "5.1.10", "5.1.10")
date <- as.Date(date, "%d.%m.%y")
plot <- c("A","B","A","B","A","B","A","B","A","B")
value <- seq(1:10)
data.frame(date, plot, value)
first, names like ‘plot’ are already taken in R, so it’s good form to not assign values to them. First stick it into a data.frame, or similar, then use logicals: