I tried to use the function mutate(completed=ifelse()) w/o succes.
You will find below the reprex
rm(list = ls())
library(dplyr)
#>
#> Attachement du package : 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(rlang)
data<- data.frame(stringsAsFactors = FALSE,
A= c("A","B","C"),
B=c("17/05/19","","")
)
tab<-data %>%
mutate(completed=ifelse(!is.null(.data$B),"Yes","On progress"))
I should obtained "Yes" for the row A and "On progress" for the row B,C.
But that's not the fact. I obtain "Yes" in each rows.
The B == "" logical test returns TRUE if there is "", so the following part of the statement should be "On Progress" and the second part (FALSE) "Yes". Because of the danger that an entry might be " ", however, I would do the following
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(lubridate))
dat <- data.frame(stringsAsFactors = FALSE,
A= c("A","B","C"),
B=c("17/05/19","","")
)
tab <-dat %>% mutate(completed = ifelse(is.Date(ymd(B)) & !is.na(ymd(B)), "Yes","On progress"))
tab
#> A B completed
#> 1 A 17/05/19 Yes
#> 2 B On progress
#> 3 C On progress