[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
>

"Informatics" 분류의 다른 글

[R] 몫과 나머지2009/11/22
R for Mac2010/02/02
[R] R을 위한 TextMate 세팅 (Mac)2010/01/19
2009/11/20 22:41 2009/11/20 22:41
JUNN
Informatics 2009/11/20 22:41

트랙백 주소 : http://www.junn.net/tt/trackback/356

댓글을 달아 주세요

[로그인][오픈아이디란?]

Powerd by Textcube,designed by criuce, Revised by JUNN