RISE_FJ/T1_child_sampling/O3_T1_FJ-revisits.R

setwd("Z:/Data Files/Data Files Objective 2/7th May")
form1 <- read_csv (file="RISE_consent_FJ_2019_final-consent_form1.csv")
consent_temp <- read_csv (file="RISE_consent_FJ_2019_final.csv")

consent_1 <- left_join (consent_temp, form1, by = c("KEY" = "PARENT_KEY")) %>%
  select (community_name, house_no, hhd_head_name, consent_form1_yn, phone_y_no)

setwd("Z:/Data Files/Data Files Objective 3")
consent_2 <- read_csv (file = "consent_FJ_v1.csv")

consent_2 <- consent_2 %>% filter (phone_yn == 1) %>%
  select (settlement_name, extract_house_no, hhd_head_name, consent_form1_yn, phone_y_no) %>%
  rename (community_name = settlement_name, house_no = extract_house_no)

revisits <- child %>% filter (settlement_barcode == "Kinoya" | settlement_barcode == "Lobau" |
                                settlement_barcode == "Wailea" | settlement_barcode == "Muanivatu") %>%
  select (settlement_barcode, extract_house_no, hhd_id, hhd_name, child_name, child_dob,
          survey_status, survey_status_other, interviewer_notes, today)

test <- left_join (revisits, consent_1, by = c("settlement_barcode" = "community_name",
                                               "extract_house_no" = "house_no"))
test2 <- left_join (test, consent_2, by = c("settlement_barcode" = "community_name",
                                            "extract_house_no" = "house_no"))

revisits_final <- test2 %>%
  mutate (phone_num = ifelse(is.na(phone_y_no.x), phone_y_no.y, phone_y_no.x),
          hhd_head_name = ifelse(is.na(hhd_head_name.x), hhd_head_name.y, hhd_head_name.x)) %>%
  rename (settlement = settlement_barcode, house_no = extract_house_no) %>%
  select (today, settlement, house_no, hhd_head_name, phone_num, child_name,
          survey_status, survey_status_other, interviewer_notes) %>%
  arrange (settlement, house_no, desc(today)) %>%
  distinct (settlement, house_no, .keep_all = TRUE) %>%
  filter (survey_status != 1) %>%
  filter (survey_status != 7) %>%
  filter (survey_status != 8) %>%
  select (settlement, house_no, hhd_head_name, phone_num, child_name,
          survey_status_other, interviewer_notes)

write_csv(revisits_final, path = "Z:/Reports/Objective 3/O3_Revisits/revisits.csv")
Monash-RISE/riseR documentation built on Dec. 11, 2019, 9:49 a.m.