I have index ( of a vector ) values of say tempin<-c(1 31 61 91 121 all the way upto 1411) What I want is a function that takes in a number say, x = 5, and gives me an new vector of tempout<-1 6 31 36 91 96 121 126 .......... 1411 1416 This can't be so hard but I can't get it and I've honestly tried. Obviously, tempin + 5 gives me the missing values but I don't know how to interwine them in the order above. Thanks for any help you can provide. mark -------------------------------------------------------- This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}
Oops, my tempout shoud be 1 6 31 36 61 66 91 96 121 126 etc. I skipped 61 and 66 in the email below. I'm sorry fot he confusion. -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Leeds, Mark (IED) Sent: Sunday, November 12, 2006 5:20 PM To: r-help at stat.math.ethz.ch Subject: [R] I think a simple question I have index ( of a vector ) values of say tempin<-c(1 31 61 91 121 all the way upto 1411) What I want is a function that takes in a number say, x = 5, and gives me an new vector of tempout<-1 6 31 36 91 96 121 126 .......... 1411 1416 This can't be so hard but I can't get it and I've honestly tried. Obviously, tempin + 5 gives me the missing values but I don't know how to interwine them in the order above. Thanks for any help you can provide. mark -------------------------------------------------------- This is not an offer (or solicitation of an offer) to buy/se...{{dropped}} ______________________________________________ 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. -------------------------------------------------------- This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}
does getIdx <- function(tmpin, x){ tmp2 = tmpin + x out = sort(c(tmpin, tmp2)) out = out[out<=max(tmpin)] return(out) } do what you want? b On Nov 12, 2006, at 5:20 PM, Leeds, Mark ((IED)) wrote:> I have index ( of a vector ) values of say > > tempin<-c(1 31 61 91 121 all the way upto 1411) > > What I want is a function that takes in a number say, x = 5, and gives > me an new vector > of > > tempout<-1 6 31 36 91 96 121 126 .......... 1411 1416 > > This can't be so hard but I can't get it and I've honestly tried. > Obviously, tempin + 5 gives me the missing values but I don't know how > to interwine them in the order above. Thanks for any help > you can provide. > > mark > -------------------------------------------------------- > > This is not an offer (or solicitation of an offer) to buy/se... > {{dropped}} > > ______________________________________________ > 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.
tempin <- seq(1, 1411, by=30) tempout <- array(data=NA, dim=length(tempin)*2) tempout[seq(1,length(tempin)*2, by=2)]<-tempin tempout[seq(2,length(tempin)*2, by=2)]<-tempin+5 Is this what you're looking for? Jeff. On Nov 12, 2006, at 5:20 PM, Leeds, Mark (IED) wrote:> I have index ( of a vector ) values of say > > tempin<-c(1 31 61 91 121 all the way upto 1411) > > What I want is a function that takes in a number say, x = 5, and gives > me an new vector > of > > tempout<-1 6 31 36 91 96 121 126 .......... 1411 1416 > > This can't be so hard but I can't get it and I've honestly tried. > Obviously, tempin + 5 gives me the missing values but I don't know how > to interwine them in the order above. Thanks for any help > you can provide. > > mark > -------------------------------------------------------- > > This is not an offer (or solicitation of an offer) to buy/se... > {{dropped}} > > ______________________________________________ > 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.
On Sun, 2006-11-12 at 17:20 -0500, Leeds, Mark (IED) wrote:> I have index ( of a vector ) values of say > > tempin<-c(1 31 61 91 121 all the way upto 1411) > > What I want is a function that takes in a number say, x = 5, and gives > me an new vector > of > > tempout<-1 6 31 36 91 96 121 126 .......... 1411 1416 > > This can't be so hard but I can't get it and I've honestly tried. > Obviously, tempin + 5 gives me the missing values but I don't know how > to interwine them in the order above. Thanks for any help > you can provide. > > markHi Mark, ?sort, as in, use sort on the concatenated vector of data and (data + 5): ## dummy data> dat <- floor(seq(1, 1411, length = 20)) > dat[1] 1 75 149 223 297 372 446 520 594 668 743 [12] 817 891 965 1039 1114 1188 1262 1336 1411 ## simply sort dat and dat + 5, concatenated together> sort(c(dat, dat + 5))[1] 1 6 75 80 149 154 223 228 297 302 372 [12] 377 446 451 520 525 594 599 668 673 743 748 [23] 817 822 891 896 965 970 1039 1044 1114 1119 1188 [34] 1193 1262 1267 1336 1341 1411 1416 which if you want a function, a suitable wrapper would be: foo <- function(x, inc) { sort(c(x, x + inc)) }> foo(dat, 5)[1] 1 6 75 80 149 154 223 228 297 302 372 [12] 377 446 451 520 525 594 599 668 673 743 748 [23] 817 822 891 896 965 970 1039 1044 1114 1119 1188 [34] 1193 1262 1267 1336 1341 1411 1416 Of course, checking for suitability of input data for foo is left up to you. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC [f] +44 (0)20 7679 0565 UCL Department of Geography Pearson Building [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street London, UK [w] http://www.ucl.ac.uk/~ucfagls/ WC1E 6BT [w] http://www.freshwaters.org.uk/ %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
"Leeds, Mark (IED)" <Mark.Leeds at morganstanley.com> writes:> I have index ( of a vector ) values of say > > tempin<-c(1 31 61 91 121 all the way upto 1411) > > What I want is a function that takes in a number say, x = 5, and gives > me an new vector > of > > tempout<-1 6 31 36 91 96 121 126 .......... 1411 1416 > > This can't be so hard but I can't get it and I've honestly tried. > Obviously, tempin + 5 gives me the missing values but I don't know how > to interwine them in the order above. Thanks for any help > you can provide.One way is c(rbind(tempin,tempin+5)) another is rep(tempin, each=2) + c(0,5) -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Perhaps a very simle way is to stack two row vectors, one containing the original series and the other the revised series and then to use the reshape command from the Matlab package. John On 12/11/06, Leeds, Mark (IED) <Mark.Leeds@morganstanley.com> wrote:> > I have index ( of a vector ) values of say > > tempin<-c(1 31 61 91 121 all the way upto 1411) > > What I want is a function that takes in a number say, x = 5, and gives > me an new vector > of > > tempout<-1 6 31 36 91 96 121 126 .......... 1411 1416 > > This can't be so hard but I can't get it and I've honestly tried. > Obviously, tempin + 5 gives me the missing values but I don't know how > to interwine them in the order above. Thanks for any help > you can provide. > > mark > -------------------------------------------------------- > > This is not an offer (or solicitation of an offer) to buy/se...{{dropped}} > > ______________________________________________ > 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. >-- John C Frain Trinity College Dublin Dublin 2 Ireland www.tcd.ie/Economics/staff/frainj/home.html mailto:frainj@tcd.ie mailto:frainj@gmail.com [[alternative HTML version deleted]]
A couple of possibilities:> sort( c(tempin, tempin+5) )Or> c( rbind(tempin, tempin+5) )HTH, -- 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 Leeds, Mark (IED) Sent: Sunday, November 12, 2006 3:20 PM To: r-help at stat.math.ethz.ch Subject: [R] I think a simple question I have index ( of a vector ) values of say tempin<-c(1 31 61 91 121 all the way upto 1411) What I want is a function that takes in a number say, x = 5, and gives me an new vector of tempout<-1 6 31 36 91 96 121 126 .......... 1411 1416 This can't be so hard but I can't get it and I've honestly tried. Obviously, tempin + 5 gives me the missing values but I don't know how to interwine them in the order above. Thanks for any help you can provide. mark -------------------------------------------------------- This is not an offer (or solicitation of an offer) to buy/se...{{dropped}} ______________________________________________ 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.