1

I want to use fill from tidyr to replace NAs in both directions.

The help informations says:

fill(data, ..., .direction = c("down", "up"))

Actually, it would be nice to use exactly this format of direction. But it does not work, as it brings an error:

Error: Unknown column down

I know the info says:

Direction in which to fill missing values. Currently either "down" (the default) or "up".

I understand the meaning of 'or'. But if I want to use both directions, do i really need to make two steps?

Here is an example:

ID <- rep(1,3)
Sess <- c(1,2,3)

df1 <- data.frame(ID,Sess)

Sess <- 2
code <- 55
df2 <- data.frame(Sess, code)

df <- left_join(df1,df2)

df %>% group_by(ID) %>% fill(code) %>% fill(code, .direction =  'up')

I was thinking about something like: fill(code, .direction = 'both')

SDahm
  • 474
  • 2
  • 9
  • 21
  • 1
    It's not clear what the result is even supposed to look like with both "down" and "up". Please provide an example. – Julius Vainora Jan 02 '19 at 13:35
  • Not sure whether this is a duplicate because i am asking for both directions. The other solutions also use a second step by rearranging the data to put the value at the last position. Or did i miss something? – SDahm Jan 02 '19 at 14:52

0 Answers0