For survival analysis I want to create a variable that selects the lowest value in a row (time to first event).
stid <- 1:5
event1 <- c(26.03, 0.39, 11.26, 0.03, 8.00)
event2 <- c(13.43, 1.68, NA, 5.87, NA)
event3 <- c(17.2, NA, NA, 9.09, NA)
event4 <- c(NA, NA, NA, 1.18, NA)
df <- data.frame(stid, event1,event2,event3,event4)
df
What i tried to achieve through which.min or with dplyr::mutate = min (but failing to do so) is to create is ..
event_first <- c(13.43, 0.39, 11.26, 0.03, 8.00)
df <- data.frame(df, event_first)
df
So the 'NA' are also excluded.
It would be very helpful! I think there possibly is a tidy solution, but have not found it yet.
I hope someone can help me :)