I have the following dataset (32000 entries) of water chemical compounds annual means organized by monitoring sites and sampling year:
data= data.frame(Site_ID=c(1, 1, 1, 2, 2, 2, 3, 3, 3), Year=c(1976, 1977, 1978, 2004, 2005, 2006, 2003, 2004, 2005), AnnualMean=c(1.1, 1.2, 1.1, 2.1, 2.6, 3.1, 2.7, 2.6, 1.9)) Site_ID Year AnnualMean 1 1976 1.1 1 1977 1.2 1 1978 1.1 2 2004 2.1 2 2005 2.6 2 2006 3.1 3 2003 2.7 3 2004 2.6 3 2005 1.9 I would like to select the data only from all monitoring sites showing at least a measurement in 2005 in their time range. With the above dataset, the expect output dataset would be:
Site_ID Year AnnualMean 2 2004 2.1 2 2005 2.6 2 2006 3.1 3 2003 2.7 3 2004 2.6 3 2005 1.9 I am completely new in R and have been spinning my head around with data manipulation, so thank you in advance!