[R] Array subscripting by names

BXC (Bendix Carstensen) bxc at novonordisk.com
Thu Mar 1 09:33:53 CET 2001


I have:

> version
         _              
platform i386-pc-mingw32
arch     x86            
os       Win32          
system   x86, Win32     
status                  
major    1              
minor    2.1            
year     2001           
month    01             
day      15             
language R              
> m <- matrix( 1:6, 2, 3 )
> rownames( m ) <- c( "a", "b" )
> m
  [,1] [,2] [,3]
a    1    3    5
b    2    4    6
> m[ "a", ]
[1] 1 3 5
> m[ "b", ]
[1] 2 4 6
> m[ match( "c", rownames(m) ), ]
[1] NA NA NA
> m[ "c", ]
Error: subscript out of bounds

I would have guessed that the last two commands always produced the same
result. 
Is this a bug or feature? If the latter is the case, what is the use of?

Bendix Carstensen

----------------------
Bendix Carstensen
Senior Statistician
Steno Diabetes Centre
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 28 25 87 38
fax: +45 44 43 73 13
bxc at novo.dk
www.biostat.ku.dk/~bxc
----------------------


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