data %>% rowwise() %>% mutate(match = case_when(c_across(cols = years2:years50), any(abs(years_standard - .x) < 1) ~ "MATCHED", TRUE ~ "NO_MATCH")
above is my code. I take my data and for each row I want to see if there is a match between "years_standard" and one of the variables between "years2:years50". I want to allow for 1 year tolerance as well . so if it one year more or less, it should be ok. my error is "must be a two-sided formula, not a double vector". is there any way u could assist?<3thankss. I also want to create a column called "first_match" that tells me what column there was the FIRST match in between "yeares2:years50" with a one year tolerance . if someone could assist there that would be so helpful too.
the output dataset would look like below
name years_standard years2 years3 ...... years50 match first_match Ryan 10 8 9 9 MATCHED years3 Adam 100 94 99 100 MATCHED years50
Assume in Adam example that the first match was in "years50".please let me know if they are questions. I appreciate.