I'm trying to learn purrr in the tidyverse and coming up short. I have a dataset that looks like:
DX1 DX2 DX3 DX4 DX5 DX6 ... DX26
2 2 2 2 4 7 ... 3
4
7 3 3 6 4
3 4
6
Where DX are various ICD9/10 codes, up to 26 total possible options. If there's no need to go past a given number of diagnoses, then the remaining DX variables are left blank.
I need to loop through all 26 DX variables and create a new variable where the value is 1 if there is any response of 4, and 0 if there is no response of 4. In other words, it should look like:
DX1 DX2 DX3 DX4 DX5 DX6 ... DX26 NewVar
2 2 2 2 4 7 ... 3 1
4 1
7 3 3 6 4 1
3 4 1
6 0
Is there a simple way to have purrr do this? Thanks in advance for any advice!