[R] names( d$columnname )
Duncan Murdoch
murdoch at stats.uwo.ca
Mon Apr 23 00:18:26 CEST 2007
On 4/22/2007 5:46 PM, ivo welch wrote:
> dear R wizards --- would it make sense for names(d$columnname) to be
> "columnname"? I can preserve the columnname through x=subset(dataset,
> select="columnname"), of course, but it would seem that x=d$columnname
> could also do this. No? Sincerely, /iaw
If I understand what you're asking, I don't think so.
d$columnname
extracts an element of the list d. It's typically some sort of vector,
and vectors don't know what their own name is.
names(d$columnname)
looks for a names attribute on that vector. If it doesn't have one,
you'll get NULL.
There are plenty of functions in R which depend on the form of the
argument passed to them, not just its value, but we shouldn't add more
without a very good reason. The change you ask for would mess up the
following calculation:
> x <- 1:26
> names(x) <- letters
> d <- list(columnname=x)
> names(d$columnname)
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p"
"q" "r"
[19] "s" "t" "u" "v" "w" "x" "y" "z"
Duncan Murdoch
More information about the R-help
mailing list