Hi, x=matrix(1:60,nr=6) I can refer the last 2 rows by x[5:6,] If I don't know the total number of rows is 6, is there a way to refer the last 2 rows? Regards, Peng
Hi, tail(x,2) or x[seq(nrow(x)-1, nrow(x)), ] HTH, baptiste 2009/9/14 Peng Yu <pengyu.ut@gmail.com>> Hi, > > x=matrix(1:60,nr=6) > > I can refer the last 2 rows by > x[5:6,] > > If I don't know the total number of rows is 6, is there a way to refer > the last 2 rows? > > Regards, > Peng > > ______________________________________________ > R-help@r-project.org mailing list > 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. >-- _____________________________ Baptiste AuguiƩ School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK http://newton.ex.ac.uk/research/emag ______________________________ [[alternative HTML version deleted]]
Try the tail() function -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Peng Yu Sent: Monday, September 14, 2009 11:32 AM To: r-help at stat.math.ethz.ch Subject: [R] How to refer to the last a few rows? Hi, x=matrix(1:60,nr=6) I can refer the last 2 rows by x[5:6,] If I don't know the total number of rows is 6, is there a way to refer the last 2 rows? Regards, Peng ______________________________________________ R-help at r-project.org mailing list 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.
> Date: Mon, 14 Sep 2009 10:32:09 -0500 > From: Peng Yu <pengyu.ut at gmail.com> > > Hi, > > x=matrix(1:60,nr=6) > > I can refer the last 2 rows by > x[5:6,] > > If I don't know the total number of rows is 6, is there a way to referBut R does known the total number of rows: it's NROW(x) -- or nrow(x) if you are sure 'x' is a matrix HTH, Giovanni> the last 2 rows? > > Regards, > Peng > > ______________________________________________ > R-help at r-project.org mailing list > 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. > >-- Giovanni Petris <GPetris at uark.edu> Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/