[R] $name vs. [["name"]]

Kjetil Kjernsmo kjetil.kjernsmo at astro.uio.no
Fri Nov 16 15:18:58 CET 2001

Dear all,

I have been away for a month, but some time ago, I noted something that
was very surprising to me. I think this example illustrates it well:
> test <- data.frame(col1 = c(1,2), col2=c(3, 4))
> test
  col1 col2
1    1    3
2    2    4
> apply(test, 1, function(x) browser())
Called from: FUN(newX[, i], ...)
Browse[1]> x$col1
Browse[1]> x[["col1"]]
[1] 1
Browse[1]> x[["col2"]]
[1] 3
Browse[1]> x$col2

it seems like the $name notation and the [["name"]] notation are
different, yet, what I understand from the intro, they should be

What's the deal?


Kjetil Kjernsmo
Graduate astronomy-student                    Problems worthy of attack
University of Oslo, Norway            Prove their worth by hitting back
E-mail: kjetikj at astro.uio.no                                - Piet Hein
Homepage <URL:http://folk.uio.no/kjetikj/>
Webmaster at skepsis.no                            OpenPGP KeyID: 6A6A0BBC

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list