Hi,
My guru andresrcs helped me to create the code merging some string variables:
source <- data.frame(
stringsAsFactors = FALSE,
URN = c("aaa", "bbb", "ccc", "ddd"),
Name = c("xxx", "xxx", "yyy", "yyy"),
Date = c("2019-04-29", "2019-11-04", "2019-06-18", "2019-06-16"),
CommQ1 = c("nein", NA, "Kein Kommentar ", "keine Ahnung"),
CommQ2 = c("xxx", "Kein Kommentar", "nein.",NA),
CommQ3 = c("Reperaturkosten stimmten", "nein", "aa", "keine Ahnung "),
Q4 = c(2019, 2020, 2020, 2021),
Q5 = c(10, 9, 8, 5)
)
blank_statements <- regex("^(Kein\\sKommentar|keine\\sAhnung|
nein)$", ignore_case = TRUE, multiline = TRUE)
library(tidyverse)
comments <- source %>%
mutate(across(contains("Comm"), ~str_remove_all(.x, blank_statements)),
across(contains("Comm"), ~str_remove_all(.x, "^.{1,7}$"))) %>%
unite("all_comments", contains("Comm"), sep = "/", remove = FALSE, na.rm = FALSE) %>%
mutate(across(contains("comments"), ~ str_remove_all(.x, "NA")),
across(contains("comments"), ~ str_remove_all(.x, "[:cntrl:]")),
across(contains("comments"), ~ str_replace_all(.x, "\\s\\s+", " ")),
across(contains("comments"), ~ str_replace_all(.x, "//+", "/")),
across(contains("comments"), ~ str_remove (.x, "/$")),
across(contains("comments"), ~ str_remove (.x, "^/")))
comments
Most of impressions from this list:
blank_statements <- regex("^(Kein\\sKommentar|keine\\sAhnung|
nein)$", ignore_case = TRUE, multiline = TRUE)
are picked up correctly but, for some reason, the phrases with spaces after them ("keine Ahnung ", "Kein Kommentar ") are not.
What am I doing wrong?