jeudi 3 juin 2021

Object created even the if statement is not satisfied in r [closed]

I have only one object in my environment :

> y
Error: object 'y' not found
> x
[1]  4 NA NA

When I run the following if statement (if returns FALSE, so I assumed the statement inside if is not run)

if (length(x[!is.na(x)]>1)){
    y=rep(NA,length(x[!is.na(x)])-1);
    for (i in 1:length(y)){
        y[i]=x[!is.na(x)][i+1]-x[!is.na(x)][i]
    }}

x remains the same but y is created

> y
[1] NA

I expected no object named y is found. Why is it? Is there a way I make the if statement not run?

Aucun commentaire:

Enregistrer un commentaire