Charles C. Berry
2001-Oct-08 17:43 UTC
[Rd] NA as names of vector from subscripted matrix == bug ?
Is this a bug?> matrix(1:4,nc=2,dimnames=list(1:2,1:2))[c(1,3)]1 NA 1 3 It has some annoying consequences, e.g.> median( matrix(1:9,nc=3,dimnames=list(1:3,1:3))[1,,drop=F] )NA 4>The above was for Version: platform = sparc-sun-solaris2.7 arch = sparc os = solaris2.7 system = sparc, solaris2.7 status = major = 1 minor = 3.0 year = 2001 month = 06 day = 22 language = R The behavior seems to differ slightly in 1.3.1. On Windows 1.3.1 matrix(1:9,nc=3,dimnames=list(1:3,1:3))[ cbind(1:3,1:3) ] omits the names (as is my preference). Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry@tajo.ucsd.edu UC San Diego http://hacuna.ucsd.edu/members/ccb.html La Jolla, San Diego 92093-0645 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thomas Lumley
2001-Oct-08 17:50 UTC
[Rd] NA as names of vector from subscripted matrix == bug ?
On Mon, 8 Oct 2001, Charles C. Berry wrote:> > Is this a bug? > > > matrix(1:4,nc=2,dimnames=list(1:2,1:2))[c(1,3)] > 1 NA > 1 3Perhaps a clearer example is> matrix(1:4,nc=2,dimnames=list(LETTERS[1:2],LETTERS[3:4]))->a > a[1]A 1> a[2]B 2> a[3]NA 3> a[4]NA 4>It's at least a wart that you sometimes get the row names and sometimes NA. OTOH it's not clear what the names of a vector extracted from a matrix *should* be if the vector isn't a single row or column. -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._