[R] Weird behavior with names()

Christian Posse posse at talariainc.com
Wed Jul 14 20:30:51 CEST 1999


Dear R fellows,

Is the following a feature or a bug of names() ??
It does  not seem to be reported as a bug in the R Bug Tracking System.


(RedHat 6.0, R-0.64.2 compiled from source, not RPM).

# a trivial test
x <- 1:5
y <- 6:10
names(x) <- c("a", "b", "c", "d", "e")
names(y) <- c("a", "b", "c", "d", "e")
 xy <- cbind(x,y)

## test names()

>  names(x)
[1] "a" "b" "c" "d" "e"
>  names(xy)
NULL
>  names(xy[,1])
[1] "a" "b" "c" "d" "e"


So far, so good.  But now look at what happens when I tried
to extract from the array:

>  names(x[-(1:3)])
[1] "d" "e"
 >  names(xy[-(1:3),1])                   it works
[1] "d" "e"
> names(xy[,1])[-(1:3)]                 it works too.....
[1] "d" "e"

>  names(x[-(1:4)])
[1] "e"
>  names(xy[-(1:4),1])
NULL                                                   ??????? should be
"e"
>  names(xy[,1])[-(1:4)]                That works......
[1] "e"

Similarly

>  names(x[5])
[1] "e"
>  names(x[4:5])
[1] "d" "e"
>  names(xy[5,1])
NULL                                                 ????????
>  names(xy[4:5,1])
[1] "d" "e"


Thanks for enlightening me!
Christian

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