I have two dataset that I want to merge and calculate the population per state in a specific year. Dataset 1 contains the output as shown in the picture. Dataset 2 contains the population per state in specific year (see picture 2). I want to merge and mutate the dataset to get the dataset as shown in picture 3. To clarify: I want to create a new column with the population of a state in the noticed year.
states <- states %>%
rename(
'yr' = 'Year'
)
merge <- merge(tornadoes, states, by = 'yr')
Example Dataset 1
num yr mo dy time state magnitude injuries fatalities crop_loss
1 1 1950 1 3 11:00:00 MO 3 3 0 0
2 1 1950 1 3 11:10:00 IL 3 0 0 0
3 2 1950 1 3 11:55:00 IL 3 3 0 0
4 3 1950 1 3 16:00:00 OH 1 1 0 0
5 4 1950 1 13 05:25:00 AR 3 1 1 0
Example Dataset 2
Read more here: https://stackoverflow.com/questions/65720913/merging-two-dataset-with-dplyr
Content Attribution
This content was originally published by Frank van Onna at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.