[R] Rule for accessing attributes?

From: Tribo Laboy <tribolaboy_at_gmail.com>
Date: Thu, 27 Mar 2008 13:16:21 +0900

Hi !

I am a new user and quite confused by R-indexing.

Make a list and get the attributes
lst <- list(x = 1:3, y = 4:6, z = 7:9)

This returns:

[1] "x" "y" "z"

I can easily do:

nm <-names(lst)


nm <-attr(lst,"names")

which both return the assigned names of the named list 'lst', but why then this doesn't work:



I am confused ... Moreover, I noticed that some of the objects (e.g. plot objects returned by ggplot) also have attributes when queried by the 'attributes' function, but they are accessible by the $ notation. (e.g.

xydf <- data.frame(x = 1:5, y = 11:15)
plt <- ggplot(data = xydf, aes(x = x,y = y)) + geom_point() attributes(plt)

Now we can change the title:

plt$title <- "My Title"

So is it some inconsistency or am I missing something important?

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 27 Mar 2008 - 04:20:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 27 Mar 2008 - 17:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive