Hello so I have two data sets I am trying to combine. The problem is I need to combine them by a certain column and certain values in the column. They both have a column called player_id. One data set has only players ids. First data set
The second data set has the number of home runs a player had and the player id. The problem is the second dataset has a ton of irrelevant players I don't need. So I need to merge them just by the player ids from data set 1. data set 2
Here is my code, the combine does not work because It brings all of the players ids from both data sets.
player2 = subset(player, select = c(player_id, birth_state))
player.mt <- player[ which(player$birth_state =='MT'),]
player.mt2 = subset(player.mt, select = c(player_id))
batting.hr <- subset(batting, select = c(player_id, hr))
batting.hr
combine <- merge(player.mt2, batting.hr, by=c("player_id"), all=TRUE)