[R] - Using a Loop To Make Code Compatible With R - | SheCodes

[R] - Using a Loop To Make Code Compatible With R

Learn how to use looping and code to check if a specific code appears in a R data frame. Set the variable for the ID to 0 or 1 if the code appears or not.

More coding questions about R

👩‍💻 Technical question

Asked 3 years ago in R by Mornie

I have a data frame with variables for participants ID, length of hospital stay, disease and whether they had stayed in hospital over the study period. There are multiple rows for each ID, as people have multiple values for the disease and length of hospital variable. I want a piece of code that goes through each group of IDs, notes if someone has been in hospital longer then 1 day and if they have I want to fill in the rest of the ID rows with 1. Could you write this code so it is compatible with R?