0

I have a very basic question:

I have a dataframe like so:

> head(xxx)
# A tibble: 6 x 2
  perim                                   no
  <chr>                                   <chr>   
1 NA                                      9999-048
2 VALUE 1                                 9999-048
3 NA                                      9999-048
4 NA                                      9999-048
5 NA                                      9999-041
6 VALUE 2                                 9999-041

I have a grouping variable, no and I want to assign each element in perim with the corresponding value, with currently only one observation per no-group having a value. My desired result would look like this:

 perim                                   no
  <chr>                                   <chr>   
1 VALUE 1                                9999-048
2 VALUE 1                                9999-048
3 VALUE 1                                9999-048
4 VALUE 1                                9999-048
5 VALUE 2                                9999-041
6 VALUE 2                                9999-041

I know there must be an easy way to go about this, but I seem to be stuck. Any help is very appreciated!

heck1
  • 714
  • 5
  • 20
  • 1
    Use `na.locf` from `zoo` or `fill` from `tidyr` – akrun Jan 04 '19 at 10:14
  • 1
    look here: https://stackoverflow.com/questions/53210281/how-to-replace-nan-value-with-previous-non-nan-within-group/53210336#53210336 – RLave Jan 04 '19 at 10:15
  • 2
    @RonakShah Yes, thanks. Just wanted to make sure OP looks into the 'correct direction'. – markus Jan 04 '19 at 10:21

0 Answers0