-1

Good day,

I have a dataset similar to that attached image and would like to mutate the People_ID to match the complete rows in R programming language.

enter image description here

stefan
  • 90,330
  • 6
  • 25
  • 51
Connie
  • 35
  • 3
  • 2
    Welcome to SO! It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data and the code you have tried. Also, please do not post an image of code/data/errors [for these reasons](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557). Just include the code, console output, or data (e.g., dput(head(x)) or data.frame(...)) directly. – stefan Aug 07 '22 at 20:33
  • 1
    This said: Have a look at e.g. `tidyr::fill` to fill up your `People_ID` column. – stefan Aug 07 '22 at 20:34

1 Answers1

0

As mentioned before, tidyr::fill should work fine if all of your results are in order; however, if you need to match based on ID, something like this should work (where df = your raw dataset):

lookup <- df[df$people_id != "",]
final <- merge(lookup, df, by="distinct_id", all = TRUE)