Hi all, I want to make a vector with the third column of a matrix, but only for the 2+3n rows of the matrix, with n being an entire number from 0 to a million. How can I do that in an easy way? Thanks in advance, Juan Pablo [[alternative HTML version deleted]]
Hi, Example: n <- 1:10 mat[2+3*n,3] #Where mat is the matrix Is what you want? -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O On 05/07/07, Juan Pablo Fededa <jpfededa@gmail.com> wrote:> > Hi all, > > I want to make a vector with the third column of a matrix, but only for > the > 2+3n rows of the matrix, with n being an entire number from 0 to a > million. > How can I do that in an easy way? > Thanks in advance, > > Juan Pablo > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@stat.math.ethz.ch 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. >[[alternative HTML version deleted]]
Or an alternative to Henrique's if you want to select all the rows from row 2 up to the 3*n row this may work. n <- 2 myvector <- data1[2:(2*n), 3] --- Juan Pablo Fededa <jpfededa at gmail.com> wrote:> Hi all, > > I want to make a vector with the third column of a > matrix, but only for the > 2+3n rows of the matrix, with n being an entire > number from 0 to a million. > How can I do that in an easy way? > Thanks in advance, > > Juan Pablo > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
One approach is to use the fact that vectors are automatically replicated to the correct length when subscripting, so you can do something like:> my.matrix[ c(FALSE,TRUE,FALSE), 3 ]To get every 3rd element starting at the 2nd element, and the 3rd column. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Juan > Pablo Fededa > Sent: Thursday, July 05, 2007 11:30 AM > To: r-help at stat.math.ethz.ch > Subject: [R] help with vector construction > > Hi all, > > I want to make a vector with the third column of a matrix, > but only for the > 2+3n rows of the matrix, with n being an entire number from 0 > to a million. > How can I do that in an easy way? > Thanks in advance, > > Juan Pablo > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >