Try:

x <- 1:444
start<-2
x[c(rep(FALSE,start-1),TRUE, rep(FALSE, 36-start+1))]
# [1]   2  39  76 113 150 187 224 261 298 335 372 409
start<-30
x[c(rep(FALSE,start-1),TRUE, rep(FALSE, 36-start+1))]
# [1]  30  67 104 141 178 215 252 289 326 363 400 437
start<-37
x[c(rep(FALSE,start-1),TRUE, rep(FALSE, 36-start+1))]
# [1]  37  74 111 148 185 222 259 296 333 370 407 444



Clint Bowman                    INTERNET:       cl...@ecy.wa.gov
Air Quality Modeler             INTERNET:       cl...@math.utah.edu
Department of Ecology           VOICE:          (360) 407-6815
PO Box 47600                    FAX:            (360) 407-7534
Olympia, WA 98504-7600

        USPS:           PO Box 47600, Olympia, WA 98504-7600
        Parcels:        300 Desmond Drive, Lacey, WA 98503-1274

On Tue, 18 Sep 2012, eliza botto wrote:


Dear useRs,
i had a matrix with 31 rows and 444 columns and i wanted to extract every 37th 
column of that matrix starting from 1. more precisely i wanted to select 
columns 1, 38,75, 112 and so on. then doing the same by starting from column 
number 2(2,39,76,113.......).
i was advised to use
x[c(TRUE, rep(FALSE, 36)),]
i works if it is start from first column but as i am very new to R i wanted to 
know what to do to make it work if i want to start column selection from column 
2 and then from column 3 and so on.
sorry for bothering you once again..
regards
eliza


From: eliza_bo...@hotmail.com
To: michael.weyla...@gmail.com
Date: Tue, 18 Sep 2012 15:06:18 +0000
CC: r-help@r-project.org
Subject: Re: [R] extracting column and regular interval in R


thnkyou very much micheal.
i worked!!!
regards
eliza


From: michael.weyla...@gmail.com
Date: Tue, 18 Sep 2012 15:58:31 +0100
Subject: Re: [R] extracting column and regular interval in R
To: eliza_bo...@hotmail.com
CC: r-help@r-project.org

x[c(TRUE, rep(FALSE, 36)),]

and let recycling work its magic!

To concretize:

x <- 1:100

x[c(TRUE, rep(FALSE, 4))]

Cheers,
Michael

On Tue, Sep 18, 2012 at 3:55 PM, eliza botto <eliza_bo...@hotmail.com> wrote:

Dear R users,
i have a matrix with 31 rows and 444 columns and i want to extract every 37th 
column of that matrix starting from 1. more precisely i want to select columns 
1, 38,75, 112 and so on. then doing the same by starting from column number 
2(2,39,76,113.......).
i know that there is a manual way of doing it but i wanted to make it more 
quickly as i have fairly large data to dealth with.

thanks in advance
eliza
[[alternative HTML version deleted]]

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

[[alternative HTML version deleted]]

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

        [[alternative HTML version deleted]]

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


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

Reply via email to