For instance, I have a vector like this
x <- c(NA, NA, NA, 12, NA)
I want R to print the first non-NA element (12) without using which or downloading packages. I guess I should make a condition that is.na(x) = FALSE
but I don't know how.
For instance, I have a vector like this
x <- c(NA, NA, NA, 12, NA)
I want R to print the first non-NA element (12) without using which or downloading packages. I guess I should make a condition that is.na(x) = FALSE
but I don't know how.
Here are couple of ways -
#1.
na.omit(x)[1]
#[1] 12
#2.
x[!is.na(x)][1]
#[1] 12