I have two vectors min 0.2, 0.3, 0.6, 0.1 max 0.4,0.5,0.7,0.4 Is there a way to combine these two vector so that the values will be taken from the vectors alternating so that I will get a new minmaxminmaxminmax-vector? minmax 0.2,0.4,0.3,0.5,0.6,0.7,0.1,0.4 Any help is much appreciated -- View this message in context: http://r.789695.n4.nabble.com/combine-vectors-in-an-alternating-way-tp3003742p3003742.html Sent from the R help mailing list archive at Nabble.com.
one way is the following: min.x <- c(0.2, 0.3, 0.6, 0.1) max.x <- c(0.4, 0.5, 0.7, 0.4) c(rbind(min.x, max.x)) I hope it helps. Best, Dimitris On 10/20/2010 2:13 PM, fugelpitch wrote:> > I have two vectors > > min > 0.2, 0.3, 0.6, 0.1 > > max > 0.4,0.5,0.7,0.4 > > Is there a way to combine these two vector so that the values will be taken > from the vectors alternating so that I will get a new > minmaxminmaxminmax-vector? > > minmax > 0.2,0.4,0.3,0.5,0.6,0.7,0.1,0.4 > > Any help is much appreciated-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/
Try this: c(matrix(c(Min, Max), 2, byrow = T)) On Wed, Oct 20, 2010 at 10:13 AM, fugelpitch <jonas@runtimerecords.net>wrote:> > I have two vectors > > min > 0.2, 0.3, 0.6, 0.1 > > max > 0.4,0.5,0.7,0.4 > > Is there a way to combine these two vector so that the values will be taken > from the vectors alternating so that I will get a new > minmaxminmaxminmax-vector? > > minmax > 0.2,0.4,0.3,0.5,0.6,0.7,0.1,0.4 > > Any help is much appreciated > -- > View this message in context: > http://r.789695.n4.nabble.com/combine-vectors-in-an-alternating-way-tp3003742p3003742.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
fugelpitch <jonas <at> runtimerecords.net> writes:> I have two vectors > > min > 0.2, 0.3, 0.6, 0.1 > > max > 0.4,0.5,0.7,0.4 > > Is there a way to combine these two vector so that the values will be taken > from the vectors alternating so that I will get a new > minmaxminmaxminmax-vector? > > minmax > 0.2,0.4,0.3,0.5,0.6,0.7,0.1,0.4 >c(rbind(min,max)) [i.e., combine the vectors into a two-row matrix and then flatten it, using the special knowledge that R stores matrices in column-wise order]