I have this tibble (transactions) A tibble: 13 × 2
START_DATE CHANNEL_LVL1
<chr> <chr>
1 NA Website
2 2023-01-31 Website
3 NA WalkIn
4 2023-01-31 Marketplace
5 NA Marketplace
6 2023-01-31 Marketplace
7 2023-01-31 Call Center
8 2023-01-31 Marketplace
9 2023-01-31 Marketplace
10 NA WalkIn
11 2023-01-31 Website
12 2023-01-31 Website
13 2023-01-31 Marketplace
I want to check for every row if( (is.na(START_DATE) && CHANNEL_LVL1 =="WalkIn")
. If that's true, I want to replace NA
with date_to_set
.
I tried this approach
transactions <- transactions %>%
mutate(
START_DATE = ifelse(is.na(START_DATE) & CHANNEL_LVL1 == "WalkIn", date_to_set, as.character(START_DATE)
)
It produces this error :
Error in
mutate()
: ! Problem while computingSTART_DATE = ifelse(CHANNEL_LVL1 == "WalkIn" & is.na(START_DATE), date, START_DATE)
. Caused by error: !START_DATE
must return compatible vectors across groups. Runrlang::last_error()
to see where the error occurred. Called from: signal_abort(cnd, .file)
I have also tried case_when approach to no avail.
Any help will be appreciated!