[R] documentation inconsistency for [.data.frame ?

Tony Plate tplate at blackmesacapital.com
Wed Jun 5 00:12:50 CEST 2002


(Using R1.5.0 patched for Windows)
Subscripting rows of data.frame only sometimes does what the documentation 
says:

>      When `[.data.frame' is used for subsetting rows of a `data.frame',
>      it returns a dataframe with unique row names, using `make.names( *
>      , unique = TRUE)', see the `swiss' example below.

Row names seem to be modified in this way only when row indices pick out 
non-existing or non-unique rows.

Splus6.0 for Windows has similar behavior, though the details are different 
(modification of row names is triggerred only by non-unique indices, 
including zeros, in Splus).  However, at least the R documentation does say 
*something* about row names being modified by make.names.

[Personally, I'd rather have a version of the dataframe class whose methods 
didn't go around modifying the row and column names I had assigned...]

Note that the documentation could be considered correct if it is assumed 
that the documentation only applies in the cases where the input data frame 
has row names that are syntactically valid variable names (i.e., will pass 
through make.names() untouched).  However, I couldn't find anything in R or 
S-plus online documentation that said this is a requirement for data frames.

 > data.frame(x=1:3,y=4:6,row.names=c("3AB","C/D","E.F"))[c(1,2,3),]
     x y
3AB 1 4
C/D 2 5
E.F 3 6
 > data.frame(x=1:3,y=4:6,row.names=c("3AB","C/D","E.F"))[c(1,2,3,NA),]
       x  y
X3AB  1  4
C.D   2  5
E.F   3  6
NA   NA NA
 > data.frame(x=1:3,y=4:6,row.names=c("AB","C/D","E.F"))[c(1,2,3,0),]
     x y
AB  1 4
C/D 2 5
E.F 3 6
 > data.frame(x=1:3,y=4:6,row.names=c("AB","C/D","E.F"))[c(1,2,3,4),]
      x  y
AB   1  4
C.D  2  5
E.F  3  6
NA  NA NA
 > data.frame(x=1:3,y=4:6,row.names=c("AB","C/D","E.F"))[c(1,1,2,3),]
     x y
AB  1 4
AB1 1 4
C.D 2 5
E.F 3 6
 > data.frame(x=1:3,y=4:6,row.names=c("AB","C/D","E.F"))[c("AB","C/D","E.F"),]
     x y
AB  1 4
C/D 2 5
E.F 3 6
 > 
data.frame(x=1:3,y=4:6,row.names=c("AB","C/D","E.F"))[c("AB","C/D","E.F","NA"),]
      x  y
AB   1  4
C.D  2  5
E.F  3  6
NA  NA NA
 > 
data.frame(x=1:3,y=4:6,row.names=c("AB","C/D","E.F"))[c("AB","C/D","E.F",NA),]
      x  y
AB   1  4
C.D  2  5
E.F  3  6
NA  NA NA
 > version
          _
platform i386-pc-mingw32
arch     i386
os       mingw32
system   i386, mingw32
status   Patched
major    1
minor    5.0
year     2002
month    05
day      16
language R




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