I have a data frame with with a release_year
column denoting the year a song was released and a play_count
column denoting how many times that song was played in a given year. Here's a reproducible example:
release_year = c(1955, 1972, 1955, 2014, 1972)
playcount = c(15, 2, 90, 6, 9)
df = data.frame(release_year, playcount)
df
How would I tidy up the data so that each year shows up only once and the total playcount is given for that year? For example, for 1955, I'll have 105 and for 1972 I'll have 11. I have tried the following code using tidyr:
gather(key = release_year, value = frequency, `1955`:`2014`)
but an error says the object is not found. Is there a better function than gather()
that I should use here?