I am trying to create a new variable that consists of the patients weight in kg at the time of visit 1, but I am having trouble with the logic. I have tried the following code but have have no luck
WL_A <- function(visitnum, Weight_KG) {
if (visitnum == 1)
return(Weight_KG)
}
data
structure(list(Sid = structure(1:5, .Label = c("A", "B", "C",
"D", "E"), class = "factor"), Weight_KG = c(100L, 500L, 70L,
90L, 82L), visitnum = c(1L, 2L, 1L, 1L, 12L), BMI = c(13L, 25L,
20L, 18L, 7L)), .Names = c("Sid", "Weight_KG", "visitnum", "BMI"
), class = "data.frame", row.names = c("1", "2", "3", "4", "5"))