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')