I have a dataframe of US zipcodes and I want to add a sequence of numbers to each unique zipcode while repeating the rest of the rows. Right now, my data looks like so:
zip city state_name
<chr> <chr> <chr>
1 01001 Agawam Massachusetts
2 01002 Amherst Massachusetts
3 01003 Amherst Massachusetts
4 01005 Barre Massachusetts
5 01007 Belchertown Massachusetts
For each row, I'd like it to look like this, (for each zipcode.)
zip city state_name Num
<chr> <chr> <chr>
01001 Agawam Massachusetts .8
01001 Agawam Massachusetts 1.0
01001 Agawam Massachusetts 1.2
01001 Agawam Massachusetts 1.4
And so on for the rest of the rows.
Data here:
structure(list(zip = c("01001", "01002", "01003", "01005", "01007"
), city = c("Agawam", "Amherst", "Amherst", "Barre", "Belchertown"
), state_name = c("Massachusetts", "Massachusetts", "Massachusetts",
"Massachusetts", "Massachusetts")), row.names = c(NA, -5L), class = c("tbl_df",
"tbl", "data.frame"))