[R] 정적 변수 선언
Locking
> a <- 1
> lockBinding("a", globalenv())
> a <- 2
Error: cannot change value of locked binding for 'a'You can use 'local'
내부 정적 변수
> counter()
> # create a function with a 'local static' variable
> counter <- local({
+ i <- 0
+ function() {
+ i <<- i + 1
+ i
+ }
+ })
>
> counter()
[1] 1
> counter()
[1] 2
> i <- 42 # change 'i' at this level
> counter() # has not effect on the 'counter' i which is local
[1] 3
>
> a <- 1
> lockBinding("a", globalenv())
> a <- 2
Error: cannot change value of locked binding for 'a'You can use 'local'
내부 정적 변수
> counter()
> # create a function with a 'local static' variable
> counter <- local({
+ i <- 0
+ function() {
+ i <<- i + 1
+ i
+ }
+ })
>
> counter()
[1] 1
> counter()
[1] 2
> i <- 42 # change 'i' at this level
> counter() # has not effect on the 'counter' i which is local
[1] 3
>
"Informatics" 분류의 다른 글
| [R] 몫과 나머지 | 2009/11/22 |
| R for Mac | 2010/02/02 |
| [R] R을 위한 TextMate 세팅 (Mac) | 2010/01/19 |
Informatics
2009/11/20 22:41




댓글을 달아 주세요