>From one Jean to another ... A[i, , drop=FALSE] On Sat, Mar 21, 2015 at 6:04 AM, <jean.cour...@math.u-psud.fr> wrote:
> My question must be a trivial one. > > There is automatic coercicion to vector when extracting only one line of a > matrix. > # example > A = matrix(1:12,3,4) > rownames(A) = c('a1','a2','a3') > > i = 1:2 > A[i,] > # [,1] [,2] [,3] [,4] > # a1 1 4 7 10 matrix > # a2 2 5 8 11 > > i = 1 > A[i,] > # [1] 1 4 7 10 vector !!! > > # to get the rowname, it is necessary to do > rownames(A)[i] > # [1] "a1" > > Is it possible to get a (1,4)-matrix (without testing length(i) ) ? I see > nothing in options()... > > Jean Coursol > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.