Hi I'm trying two combine two vectors that have different lengths. This without recursive the shorter one. E.g., a <- seq(1:3) b <- seq(1:6) Thanks in advance Serdar [[alternative HTML version deleted]]
On 27/11/10 16:04:35, Serdar Akin wrote:> I'm trying two combine two vectors that have different lengths. This without > recursive the shorter one. E.g., > > a <- seq(1:3) > b <- seq(1:6)If that means your output should be (1 2 3 1 2 3 4 5 6) then c <- c(a,b) should solve this. Looks like _the_ basic vector operation. Georg. -- Research Assistant Otto-von-Guericke-Universit?t Magdeburg research at georgruss.de http://research.georgruss.de
On 27/11/10 19:04:27, Serdar Akin wrote:> Hi > No its has to be like this: > a b > 1 1 > 2 2 > 3 3 > 4 > 5 > 6Hmm, "empty" elements in such an array? Seems not really recommended, if it's possible at all. You may try filling up the shorter vector with NA's or any other values that your application can understand appropriately. Then do rbind or cbind, as necessary. Georg. PS: you may also reply to the r-help list -- Research Assistant Otto-von-Guericke-Universit?t Magdeburg research at georgruss.de http://research.georgruss.de
Hi Serdar, One way would be: l <- list(a, b) do.call(cbind, lapply(l, function(x) x[1:max(sapply(l, length))])) HTH, Jorge On Sat, Nov 27, 2010 at 10:04 AM, Serdar Akin <> wrote:> Hi > > I'm trying two combine two vectors that have different lengths. This > without > recursive the shorter one. E.g., > > a <- seq(1:3) > b <- seq(1:6) > > Thanks in advance > > Serdar > > [[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]]
On Sat, Nov 27, 2010 at 1:56 PM, Georg Ru? <research at georgruss.de> wrote:> On 27/11/10 19:04:27, Serdar Akin wrote: >> ? ?Hi >> ? ?No its has to be like this: >> ? ?a b >> ? ?1 1 >> ? ?2 2 >> ? ?3 3 >> ? ? ?4 >> ? ? ?5 >> ? ? ?6 >Assuming the empty cells are to be NAs turn a and b into ts objects (since ts objects will cbind in the way you like) and finally turn it back into a matrix: matrix(cbind(ts(a), ts(b)), nc = 2) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com