reserved words - What do ..1 and ..2 stand for in R? -
this question has reply here:
two dots, “..” in r 2 answersquote r language definition:
notice identifiers starting period not default listed ls function , ‘...’ , ‘..1’, ‘..2’, etc. special.
the next identifiers have special meaning , cannot used object names if else repeat while function in next break true false null inf nan na na_integer_ na_real_ na_complex_ na_character_ ... ..1 ..2 etc.
however not give farther detail. elaborate?
these used positionally extract values ...
argument of function. see illustration below:
myfun <- function(...) { list(a = ..1, b = ..2, c = ..3) } myfun(1,2,3) # $a # [1] 1 # $b # [1] 2 # $c # [1] 3 myfun(3,2,1) # $a # [1] 3 # $b # [1] 2 # $c # [1] 1 myfun(1:5, "hello", letters[1:3]) # $a # [1] 1 2 3 4 5 # $b # [1] "hello" # $c # [1] "a" "b" "c"
this utilize becomes obvious if seek phone call 1 of these console:
> ..1 error: ..1 used in wrong context, no ... in
r reserved-words
No comments:
Post a Comment