HI: Could someone help me with the seq function? I have a range of values starting from 1 to 52 but I want seq to start at 27 by=2, but when it reaches 51 start with with number 1 to 25. is this possible. I can do the basics of seq() but I can't figure how to do this one. This is how I want my sequence to look like: 27 29 31 33 35 37 ............51 1 3 5 7 9 11 13 ...........25 Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA
seq()
6 messages · jim holtman, Berwin A Turlach, Stephan Kolassa +2 more
Is this what you want:
x <- seq(1, 52, 2) x
[1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51
(x + 26) %% 52
[1] 27 29 31 33 35 37 39 41 43 45 47 49 51 1 3 5 7 9 11 13 15 17 19 21 23 25
On Wed, Jan 21, 2009 at 12:29 PM, Felipe Carrillo
<mazatlanmexico at yahoo.com> wrote:
HI: Could someone help me with the seq function? I have a range of values starting from 1 to 52 but I want seq to start at 27 by=2, but when it reaches 51 start with with number 1 to 25. is this possible. I can do the basics of seq() but I can't figure how to do this one. This is how I want my sequence to look like: 27 29 31 33 35 37 ............51 1 3 5 7 9 11 13 ...........25 Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA
______________________________________________ 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.
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
G'day Felipe, On Wed, 21 Jan 2009 09:29:03 -0800 (PST)
Felipe Carrillo <mazatlanmexico at yahoo.com> wrote:
Could someone help me with the seq function? I have a range of values starting from 1 to 52 but I want seq to start at 27 by=2, but when it reaches 51 start with with number 1 to 25. is this possible. I can do the basics of seq() but I can't figure how to do this one. This is how I want my sequence to look like: 27 29 31 33 35 37 ............51 1 3 5 7 9 11 13 ...........25
Are you after something like: R> c(seq(27,51,by=2), seq(1,25,by=2)) [1] 27 29 31 33 35 37 39 41 43 45 47 49 51 1 3 5 7 9 11 13 15 17 19 21 23 [26] 25 or R> seq(1,52,by=2)[c(14:26,1:13)] [1] 27 29 31 33 35 37 39 41 43 45 47 49 51 1 3 5 7 9 11 13 15 17 19 21 23 [26] 25 ?? HTH. Cheers, Berwin =========================== Full address ============================= Berwin A Turlach Tel.: +65 6515 4416 (secr) Dept of Statistics and Applied Probability +65 6515 6650 (self) Faculty of Science FAX : +65 6872 3919 National University of Singapore 6 Science Drive 2, Blk S16, Level 7 e-mail: statba at nus.edu.sg Singapore 117546 http://www.stat.nus.edu.sg/~statba
Hi Felipe, concatenate two sequences using c(): c(seq(from=27,to=51,by=2),seq(from=1,to=25,by=2)) HTH, Stephan Felipe Carrillo schrieb:
HI: Could someone help me with the seq function? I have a range of values starting from 1 to 52 but I want seq to start at 27 by=2, but when it reaches 51 start with with number 1 to 25. is this possible. I can do the basics of seq() but I can't figure how to do this one. This is how I want my sequence to look like: 27 29 31 33 35 37 ............51 1 3 5 7 9 11 13 ...........25 Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA
______________________________________________ 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.
On Wed, 2009-01-21 at 09:29 -0800, Felipe Carrillo wrote:
HI: Could someone help me with the seq function? I have a range of values starting from 1 to 52 but I want seq to start at 27 by=2, but when it reaches 51 start with with number 1 to 25. is this possible. I can do the basics of seq() but I can't figure how to do this one. This is how I want my sequence to look like: 27 29 31 33 35 37 ............51 1 3 5 7 9 11 13 ...........25
I don't know of a way to do it with one seq() call, without further
processing, but here are two solutions:
First, just concatenate two seq() calls together:
c(seq(27, 51, by = 2), seq(1, 25, by = 2))
which could be wrapped into a function for ease of use:
bar <- function(from, to, mid, by = 2) {
c(seq(from = mid, to = to, by = by),
seq(from = from, to = mid-by, by = by))
}
Alternatively, produce the full sequence and then break if at the point
you want and return the latter half plus the first half:
foo <- function(from, to, mid, by = 2) {
SEQ <- seq(from = from, to = to, by = by)
midp <- which(SEQ == mid)
c(SEQ[midp:length(SEQ)], SEQ[1:(midp-1)])
}
In both cases I take mid to be the point you want to break at, or start
the *final* sequence from.
foo(1, 51, by = 2, mid = 27)
bar(1, 51, by = 2, mid = 27)
HTH
G
Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA
______________________________________________ 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.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090121/4ae4c159/attachment-0002.bin>
It works like a charm,thank you all for your help.
--- On Wed, 1/21/09, jim holtman <jholtman at gmail.com> wrote:
From: jim holtman <jholtman at gmail.com> Subject: Re: [R] seq() To: mazatlanmexico at yahoo.com Cc: r-help at stat.math.ethz.ch Date: Wednesday, January 21, 2009, 9:40 AM Is this what you want:
x <- seq(1, 52, 2) x
[1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51
(x + 26) %% 52
[1] 27 29 31 33 35 37 39 41 43 45 47 49 51 1 3 5 7 9 11 13 15 17 19 21 23 25
On Wed, Jan 21, 2009 at 12:29 PM, Felipe Carrillo <mazatlanmexico at yahoo.com> wrote:
HI: Could someone help me with the seq function? I have a
range of values starting from 1 to 52 but I want seq to start at 27 by=2, but when it reaches 51 start with with number 1 to 25. is this possible. I can do the basics of seq() but I can't figure how to do this one. This is how I want my sequence to look like:
27 29 31 33 35 37 ............51 1 3 5 7 9 11 13
...........25
Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA
______________________________________________ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?