I have to mutate the dataframe
and add column based on a certain word Health
in a column. This code runs fine when I run it in R
with dplyr
, but it doesn't run when I use sparklyr. This is the first time I'm using sparklyr
. How can I fix this?
bmk_tbl %>% add_column(healthcare = case_when(
grepl("Health", .$OrganizationType) ~ 1,
TRUE ~ 0), .after = "OrganizationType")
I get the following error, and I don't know how to fix it
Error in if (nrow(df) != nrow(.data)) { : missing value where TRUE/FALSE needed
I'm not sure what to try so I tried doing something like this:
bmk_tbl %>% add_column(healthcare = case_when(
(.$OrganizationType %in% c("Health") ~ 1),
TRUE ~ 0), .after = "OrganizationType")
but this won't work because there's no single word Health
in the database. It's always mixed with some other multiple words.