-1

I need to sum the results of three different parameters (1-3) into a new column called "New". The results should only be added if the SiteID is equal to 'One','Two','Three','Four','Five' & the date of sample collection is the same for each parameter. The time of collection does not matter as long as the date is the same.

I am a novice in R and tried If, While, and For loops but did not get very far...

Thank you

Below is what the results should look like: Results

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
  • Possible duplicate of [How to sum a variable by group](https://stackoverflow.com/questions/1660124/how-to-sum-a-variable-by-group) – NelsonGon May 09 '19 at 04:48

1 Answers1

3

One option would be to do a group by 'SiteID', 'Date' column and then mutate to create a new column which is the sum of 'Result'

library(dplyr)
df2 <- df1 %>%
         group_by(SiteID, Date) %>%
         mutate(New = sum(Result)) 
akrun
  • 874,273
  • 37
  • 540
  • 662