Coalesce survey responses in a dataframe

Why not to do something like this?

Q1 <- c(NA, NA, "A", NA, NA)
Q1[!is.na(Q1)]
#> [1] "A"

It would be easier to help you if you could provide a minimal REPRoducible EXample (reprex).

EDIT: Just in case you still want to follow the regex path

library(stringr)
str_extract(paste("A",NA,NA,NA,NA), "(?<!N\\s?)[A-E]")
#> [1] "A"
1 Like