I have a data frame with a list of cities and daily temperature recordings
data = data.frame(c("Chicago", "Chicago", "New York", "New York", "Denver"),
                  c(25, 36, 23, 24, 42))
I want to add a third column that is the average temperature by city
avgtemp = c(30.5, 30.5, 23.5, 23.5, 42)
I have tried to do this using the package dplyr, but have not had success. What is the best way to achieve this, noting that the full dataset contains 50,000 rows, thus I want the code to be efficient.
 
     
    