R-alpha: ?bug in [.data.frame
Peter Dalgaard BSA
p.dalgaard@kubism.ku.dk
31 Aug 1997 22:11:54 +0200
Thomas Lumley <thomas@biostat.washington.edu> writes:
>
>
> If you subscript a data frame using the names of the columns and there is
> more than one column with the same name only the first one is found.
> eg
> mm<-data.frame(1:10,log(1:10))
> names(mm)<-c("(offset)","(offset)")
> mm[,"(offset)"] # only returns first column
> mm[,"(offset)"]<-rep(1,10) # only sets first column
>
> This *is* compatible with S, but I still think it's the wrong thing to do.
This is a generic list thing. Nothing keeps you from having several
elements with the same name, you just get certain problems accessing
them.
> l<-list(1,2,3)
> names(l)<-c("a","b","b")
> l
$a
[1] 1
$b
[1] 2
$b
[1] 3
> l$b
[1] 2
I rather strongly suspect that coding for the possibility, that in a
list of vectors l$b could mean another list, would be a real pain.
I.e. you deserve what you get...
If you must have identically named columns, try something along the
lines of
> l[names(l)=="b"]
$b
[1] 2
$b
[1] 3
> l[names(l)=="b"]<-4
> l
$a
[1] 1
$b
[1] 4
$b
[1] 4
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel 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-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-