I need to append a new column to my first dataframe with the number of appearances of the corresponding id in the second dataframe. I've created a toy example to try to do this. I'm thinking it's going to require a for loop, but cannot figure it out. Here's the toy datasets:
id <- c(1:10)
gender <- c('M','M','M','F','F','F','M','F','F','F')
age <- c(23,33,45,66,12,6,18,31,26,77)
first_df <- data.frame(id,gender,age)
id <- c(1,3,8,1,2,3,7,9)
second_df <- data.frame(id)
So where id is 1 in my first_df, I would like a column that has the value 2 because it appears twice in the second_df. And for id 5 should have a 0 or NA in that new column because it does not appear in the second_df.