merge data.frames based on year and fill in missing values

前端 未结 4 1843
-上瘾入骨i
-上瘾入骨i 2020-11-29 14:22

I have two data.frames that I want to merge together. The first is:

datess <- seq(as.Date(\'2005-01-01\'), as.Date(\'2009-12-31\'), \'days\')
sample<-          


        
4条回答
  •  猫巷女王i
    2020-11-29 14:59

    If y and Z are always zero in sample you do not need them there, so all you have to do is join on year like this:

     library(dplyr)
     sample %>% mutate(a = format(Date, "%Y") %>% as.numeric) %>% 
       inner_join(a %>% select(a)) 
    

提交回复
热议问题