0

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!

  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jan 25 '23 at 14:42

0 Answers0