Q:

Returning values after last NA in a vector

Returning values after last NA in a vector
I can remove all NA values from a vector
v1 <- c(1,2,3,NA,5,6,NA,7,8,9,10,11,12)
v2 <- na.omit(v1)
v2

but how do I return a vector with values only after the last NA
c( 7,8,9,10,11,12)

Thank you for your help.

A:

You could detect the last NA with which and add 1 to get the index past the last NA and index until the length(v1):
 v1[(max(which(is.na(v1)))+1):length(v1)]
[1]  7  8  9 10 11 12

