[R] names attribute of data.frames after rbind
Angelo Canty
canty at math.mcmaster.ca
Mon Apr 26 20:38:10 CEST 2004
Hi,
If columns of a data.frame have a names attribute and we rbind two
similar data.frames together, the names of the column of the resulting
data.frame only has the correct values for the first component and
has "" in all other positions. Is this a documented "feature" or
a bug? If it is intentional, why? Here is a small example to
show what I mean. The same behaviour appears on R1.9.0 for Windows
and R1.8.1 for Solaris (I haven't got around to upgrading there yet).
> x1 <- 1:5; names(x1)=1:5
> x2 <- 6:10; names(x2)=6:10
> x1 <- data.frame(x=x1)
> x2 <- data.frame(x=x2)
> x12 <- rbind(x1, x2)
> attributes(x1$x)
$names
[1] "1" "2" "3" "4" "5"
> attributes(x2$x)
$names
[1] "6" "7" "8" "9" "10"
> attributes(x12$x)
$names
[1] "1" "2" "3" "4" "5" "" "" "" "" ""
> x21 <- rbind(x2, x1)
> attributes(x21$x)
$names
[1] "6" "7" "8" "9" "10" "" "" "" "" ""
--
------------------------------------------------------------------
| Angelo J. Canty Email: cantya at mcmaster.ca |
| Mathematics and Statistics Phone: (905) 525-9140 x 27079 |
| McMaster University Fax : (905) 522-0935 |
| 1280 Main St. W. |
| Hamilton ON L8S 4K1 |
More information about the R-help
mailing list