for loop - R - Is for(x in x) valid? -


i writing function in r , have input id numeric vector.

can write loop states:

for(id in id) {     /****/ } 

and loop on id vector variable id or cause problem?

it produce expected result destroy id right of in. within loop references id id left of in won't able reference 1 on right.

> id <-  1:3 > for(id in id) print(id) [1] 1 [1] 2 [1] 3 > id [1] 3 

try writing safer:

ids <- 1:3 for(id in ids) print(id) 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -