diff --git a/dataProcessing/testFill.R b/dataProcessing/testFill.R new file mode 100644 index 0000000000000000000000000000000000000000..1065af37d0512a691af3c7cfa58f3eea3652b1c1 --- /dev/null +++ b/dataProcessing/testFill.R @@ -0,0 +1,22 @@ +# testing methods to fill in NA + +require(tidyverse) +require(readxl) +require(here) + +testF <- paste0(here::here(), "/data/fakeTimeUseActsFile.xlsx") + +testDF <- readxl::read_xlsx(testF) + +head(testDF) + +with(testDF, table(code, text)) + +# https://stackoverflow.com/questions/40040834/replace-na-with-previous-or-next-value-by-group-using-dplyr +testFilledDF <- testDF %>% + group_by(userID) %>% + fill(code, text) %>% # first go downwards + fill(code, text, .direction = "up") # then back up to fix the ones that are left (any NA at and just after the start) + + +with(testFilledDF, table(code, text))