I am trying to create a function to create a new column in Dataframe under conditions.
I'm tryin this goal with this code:
df <- df %>%
mutate(
predecessor = pmap_chr(
list(H_code, PRIMITIVE_EFFECT_DATE),
~repetition[H_code == ..1 & ..2 > LEAVING_DATE & ..2 < LEAVING_DATE %m+% months(6)]$ID_number %>%
paste(collapse = "; "))
But i have this problem:
Error in `[.data.table`(.DT_, , `:=`(predecessor = pmap_chr(list(H_code, : Variable '1' is not found in calling scope. Looking in calling scope because this symbol was prefixed with .. in the j= parameter.
I have checked the environment of the function and df exist with the columns ("H_code", "PRIMITIVE_EFFECT_DATE", "ID_number" and "LEAVING_DATE" so, Why the Variable '1' is not in calling scope??
Thank you a lot!!
I'm tried make this code in scrip, out of the function... and works!