group_by() into fill() not working as expected

后端 未结 6 820
盖世英雄少女心
盖世英雄少女心 2020-12-31 11:02

I\'m trying to do a Last Observation Carried Forward operation on some poorly formatted data using dplyr and tidyr. It isn\'t working as I\'d expe

6条回答
  •  孤城傲影
    2020-12-31 11:25

    Two questions, does it has be duplicated and do you have to use dplyr and tidyr?

    Maybe this could be a solution?

    (
    bar <- data.frame(id=c(1,1,2,2,3,3),
                     email=c('bob@email.com', NA, 'joe@email.com', NA, NA, NA))
    )                 
    #> id         email
    #>  1 bob@email.com
    #>  1          
    #>  2 joe@email.com
    #>  2          
    #>  3          
    #>  3          
    
    (                 
    foo <- bar[!duplicated(bar$id),]
    )
    #> id         email
    #>  1 bob@email.com
    #>  2 joe@email.com
    #>  3          
    

提交回复
热议问题