group_by() into fill() not working as expected

后端 未结 6 821
盖世英雄少女心
盖世英雄少女心 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

    This is kind of ugly, but it is another option that uses dplyr and works with your sample data

    df %>%
       group_by(id) %>%
       mutate(email = email[ !is.na(email) ][1])
    

提交回复
热议问题