Re: [R] I think a simple question
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 [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Leeds, Mark (IED) Sent: Sunday, November 12, 2006 3:20 PM To: r-help@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@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. __ 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.
Re: [R] I think a simple question
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) <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] [[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.
Re: [R] I think a simple question
Much more elegant! Is there a way, from the documentation, we would know that c() and lists in general behave as they do in these two lines? Jeff. On Nov 12, 2006, at 6:32 PM, Peter Dalgaard wrote: > One way is > > c(rbind(tempin,tempin+5)) > > another is > > rep(tempin, each=2) + c(0,5) [[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.
Re: [R] I think a simple question
"Leeds, Mark (IED)" <[EMAIL PROTECTED]> 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 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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.
Re: [R] I think a simple question
On Sun, 2006-11-12 at 22:45 +, Gavin Simpson wrote: > 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. > > > >mark > > Hi Mark, > > ?sort, as in, use sort on the concatenated vector of data and (data + > 5): Whoops, my solution of course works fine if the increment (x = 5) is small compared to the difference between values in tempin, but it fails miserably with something like an increment of 100: > 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 > foo <- function(x, inc) { sort(c(x, x+inc))} > foo(dat, 100) [1]1 75 101 149 175 223 249 297 323 372 397 [12] 446 472 520 546 594 620 668 694 743 768 817 [23] 843 891 917 965 991 1039 1065 1114 1139 1188 1214 [34] 1262 1288 1336 1362 1411 1436 1511 An alternative solution that seems to work is > bar <- function(x, inc) { len <- length(x) * 2 retval <- numeric(length = len) ## identify odd/even entries inds <- as.logical(1:len %% 2) ## fill the odds (original) retval[inds] <- x ## fill the evens (incremented) retval[!inds] <- x + inc retval } > bar(dat, 100) [1]1 101 75 175 149 249 223 323 297 397 372 [12] 472 446 546 520 620 594 694 668 768 743 843 [23] 817 917 891 991 965 1065 1039 1139 1114 1214 1188 [34] 1288 1262 1362 1336 1436 1411 1511 HTH G > > ## 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]16 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]16 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/ %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ 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.
Re: [R] I think a simple question
Note, the wrapped sort is a really tight solution but won't necessarily always give you an "intertwined" array. For example, if x=31 (or basically, tempin[2] or greater), then you would get 1, 31, 32, etc. instead of 1, 32, 31 Depends on what you were looking for. Jeff. On Nov 12, 2006, at 5:45 PM, Gavin Simpson wrote: > 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. >> >>mark > > Hi 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]16 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]16 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/ > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~ > %~% > > __ > 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. __ 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.
Re: [R] I think a simple question
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. > >mark Hi 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]16 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]16 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/ %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ 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.
Re: [R] I think a simple question
Sorry to hit the list three times in a row, but forgot to create the array in the function; note, always test after doing rm(list=ls()). everyOther <- function(tempin, x){ 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+x tempout } Usage: everyOther(seq(1,1411, by=30), 5) Sorry, Jeff. On Nov 12, 2006, at 5:35 PM, Jeffrey Robert Spies wrote: > Funciton form: > > everyOther <- function(tempin, x){ > tempout[seq(1,length(tempin)*2, by=2)]<-tempin > tempout[seq(2,length(tempin)*2, by=2)]<-tempin+x > tempout > } > > Jeff. > > On Nov 12, 2006, at 5:31 PM, Jeffrey Robert Spies wrote: > >> 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@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. >> > __ 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.
Re: [R] I think a simple question
Funciton form: everyOther <- function(tempin, x){ tempout[seq(1,length(tempin)*2, by=2)]<-tempin tempout[seq(2,length(tempin)*2, by=2)]<-tempin+x tempout } Jeff. On Nov 12, 2006, at 5:31 PM, Jeffrey Robert Spies wrote: > 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@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. > __ 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.
Re: [R] I think a simple question
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@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. __ 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.
[R] I think a simple question clarification
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Leeds, Mark (IED) Sent: Sunday, November 12, 2006 5:20 PM To: r-help@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@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}} __ 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.
Re: [R] I think a simple question
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@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. __ 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.
[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@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.