df <- arrange(df, date,site,location,collar)
## how many rows of data do you have?
print(nrow(df))
## add in an identifier to check for repeats
df$match <- paste(df$date,df$site,df$location,df$collar)
## empty column to take the means of the repeated fluxes
df$meanFlux <- NA
## to all the matches
for (i in 1:length(df$match)){
if(df$smpl_no[i]>1){
wch <- which(df[,"match"]==df$match[i])
df$meanFlux[i] <- mean(df$CO2.flux_qc[wch], na.rm=T)
df$CO2.flux_qc[wch] <- df$meanFlux[i]
}
}
##slice sample by group
df %>% group_by(smpl_no) %>% slice (n=3)
## this next bit groups by 'match' and slices the first row, so we end up with a single value for every sampling
## but for repeated samplings this is a mean of all the repeats (if they weren't anyway excluded by qc).
df <- df %>% group_by(match) %>%
slice(1)