I'm trying to write a script in which within my df, I want to find in several consecutive columns (e.g. 16:25) a specific string which is a combination of "SA (string and spaces within the bracket)". If the string is present in any of the columns, it will only appear in one of them.
When that string is detected, I would like it to be moved or copied to a different column named "SA_status".
If it is not found in any of the columns, then I'd like the value for that row on SA_status to appear as NA.
I've tried to create a for loop to search in the first column, and if it wasn't found, in the next one and so on; and if it was found to stop there. Then, I have used a combination of the functions mutate(), case_when(), str_detect() to copy that value into the new column.
Finally, if after doing this process the values in the new column were still blank, I've assigned them to NA.
However, I must be doing something wrong because it is not working and I'm getting really desperate.
Could you please give me a hand? Cheers!