Every week I a incomplete dataset for a analysis. That looks like:
df1 <- data.frame(var1 = c(\"a\",\"\",\"\",\"b\",\"\"), var2 = c(\"x\",\"
The tidyr packages has the fill() function which does the trick.
fill()
df1 <- data.frame(var1 = c("a",NA,NA,"b",NA), stringsAsFactors = FALSE) df1 %>% fill(var1)