Here is my vector:
x <- c("a", "b", "c")
I am going to extract only the odd elements from the vector so I write something like this:
ifelse(length(x) > 0, x[seq(from = 1, to = length(x), by = 2)], NA)
But the result returned is just only"a". However, if I check the condition and run the TRUE statement separately, I got different results.
length(x) > 0 #TRUE
x[seq(from = 1, to = length(x), by = 2)] # "a" "c"
Does anyone know why? Thank you!
Aucun commentaire:
Enregistrer un commentaire