From 70cb65b9373178d7a501e3033b4e8861430b0025 Mon Sep 17 00:00:00 2001
From: Ben Anderson <dataknut@icloud.com>
Date: Thu, 20 Jun 2019 16:35:39 +0100
Subject: [PATCH] testng methods to fill in NA

---
 dataProcessing/testFill.R | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 dataProcessing/testFill.R

diff --git a/dataProcessing/testFill.R b/dataProcessing/testFill.R
new file mode 100644
index 0000000..1065af3
--- /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))
-- 
GitLab