vendredi 18 janvier 2019

R: Error in if argument is of length zero

I have a vector like this:

x <- c(0.9,0.9,0,0,0.9,0,0.8)

I want to eliminate all the zeros and create a new vector from it, so I have created this if statement:

if (x[i] == 0) {
y <- x[-(i)]}

But I get the following error:

Error in if (x[i] == 0) { : argument is of length zero

Anyone has a solution? Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire