Good morning,
Attached data :
id = c (2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
vm = c("13", "14", "15", "16", "17", "19", "20", "21", "22", "23"),
GE = c("0", "0", "0", "0" "0", "0", "1", "0", "1","0")
fichier <- data.frame(id, vm, GE)
Attached R code :
library(tidyverse)
fichier <- fichier %>%
mutate(statut = case_when(
fichier$vm == 13 & fichier$GE == 1 ~ "infection",
fichier$vm == 14 & fichier$GE == 1 ~ "infection",
fichier$vm == 15 & fichier$GE == 1 ~ "infection",
fichier$vm == 16 & fichier$GE == 1 ~ "infection",
fichier$vm == 17 & fichier$GE == 1 ~ "infection",
fichier$vm == 19 & fichier$GE == 1 ~ "infection",
fichier$vm == 20 & fichier$GE == 1 ~ "infection",
fichier$vm == 21 & fichier$GE == 1 ~ "infection",
fichier$vm == 22 & fichier$GE == 1 ~ "infection",
fichier$vm == 23 & fichier$GE == 1 ~ "infection",
TRUE ~ "noinfection")
)
Attached Results :
id = c (2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
vm = c("13", "14", "15", "16", "17", "19", "20", "21", "22", "23"),
GE = c("0", "0", "0", "0" "0", "0", "1", "0", "1","0"),
statut = c("noinfection", "noinfection", "noinfection", "noinfection", "noinfection", "noinfection", "infection", "noinfection", "infecton", "noinfection")
fichier <- data.frame(id, vm, GE, status)
Please, I would like to be able to complete “status” variable at vm = 18 (months) and vm = 24 (months).
a) I would like to give this variable at vm = 18
– the value 0 if GE = 0 during the previous visits of 13 to 17 months.
– the value 1 if GE = 1 during the previous visits of 13 to 17 months.
b) I would like to give this variable at vm = 24
– the value 0 if GE = 0 during the previous visits of 19 to 22 months.
– the value 1 if GE = 1 during the previous visits of 19 to 22 months.
Thank you in advance for your help !