R-alpha: "row.names<-"

Douglas Bates (bates@stat.wisc.edu)
Tue, 6 Aug 96 15:41 CDT


Message-Id: <m0unsws-0000ULC@franz.stat.wisc.edu>
Date: Tue, 6 Aug 96 15:41 CDT
From: Douglas Bates <bates@stat.wisc.edu>
To: r-testers@stat.math.ethz.ch
Subject: R-alpha: "row.names<-"

The function "row.names<-" doesn't return the modified first argument
(i.e. x) when x is a data frame.  It returns the new names as a vector
 > get("row.names<-")
 function (x, value) 
 {
	 if (!is.data.frame(x)) 
		 x <- data.frame(x, row.names = value)
	 else attr(x, "row.names") <- as.character(value)
 }
 > data(women)
 > class(women)
 [1] "data.frame"
 > women
    height weight
 1      58    115
 2      59    117
 3      60    120
 4      61    123
 5      62    126
 6      63    129
 7      64    132
 8      65    135
 9      66    139
 10     67    142
 11     68    146
 12     69    150
 13     70    154
 14     71    159
 15     72    164
 > row.names(women) <- LETTERS[1:15]
 > women
  [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O"

I think it should become

"row.names<-" := function(x,value) {
	if( !is.data.frame(x) )
		x <- data.frame(x, row.names=value)
	else
		attr(x,"row.names") <- as.character(value)
	x
}

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-