Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Do previous lines calculated influence the sequential lines in a loop for R?

$
0
0

I have this code

x=c(T,T,F,T,F)

for (i in 1:5){
  if(i > 1 & i < 5){
     x[i ] = x[i-1] & x[i+1] & x[i]

     print(x)
  } 
  else if(i < 5){
     x[i] = !x[i] | !x[i+1]
  }
}

I am trying to figure out the output it gives me

[1] FALSE FALSE FALSE  TRUE FALSE
[1] FALSE FALSE FALSE  TRUE FALSE
[1] FALSE FALSE FALSE FALSE FALSE

I am wondering if the first value x[2] (which is x[2] = T & F & T) will influence the output of the next line x[3] or if these calculations for each line are independent of each other?


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>