[R] How to make the assignment in a for-loop not affect variables outside the loop?

Peng Yu pengyu.ut at gmail.com
Sun Nov 22 15:56:13 CET 2009


I know that R is a dynamic programming language. But I'm wondering if
there is a way to make the assignment in a for-loop not affect
variables outside the loop.

> n=10
> for(i in 1:n){
+     n=3
+     print(n)
+ }
[1] 3
[1] 3
[1] 3
[1] 3
[1] 3
[1] 3
[1] 3
[1] 3
[1] 3
[1] 3
>
> print(n)
[1] 3
>




More information about the R-help mailing list