sagarnikam123
2012-Mar-15 09:08 UTC
[R] how to bind uneven column (not equal length) into matrix without recycling values
i have> x[1] 1 2 3 4 5 6> y[1] 34 5 6> z<-cbind(x,y) > zx y [1,] 1 34 [2,] 2 5 [3,] 3 6 [4,] 4 34 [5,] 5 5 [6,] 6 6 i don't want recycling, instead can we put NA /0 like below> z x y [1,] 1 34 [2,] 2 5 [3,] 3 6 [4,] 4 NA [5,] 5 NA [6,] 6 NA & want distance matrix -- View this message in context: http://r.789695.n4.nabble.com/how-to-bind-uneven-column-not-equal-length-into-matrix-without-recycling-values-tp4474304p4474304.html Sent from the R help mailing list archive at Nabble.com.
Berend Hasselman
2012-Mar-15 11:22 UTC
[R] how to bind uneven column (not equal length) into matrix without recycling values
On 15-03-2012, at 10:08, sagarnikam123 wrote:> i have >> x > [1] 1 2 3 4 5 6 >> y > [1] 34 5 6 >> z<-cbind(x,y) >> z > x y > [1,] 1 34 > [2,] 2 5 > [3,] 3 6 > [4,] 4 34 > [5,] 5 5 > [6,] 6 6 > > i don't want recycling, instead can we put NA /0 like below> z > x y > [1,] 1 34 > [2,] 2 5 > [3,] 3 6 > [4,] 4 NA > [5,] 5 NA > [6,] 6 NA >See earlier thread today on NA - data.frame library(plyr)> t(rbind.fill.matrix(matrix(x,nrow=1),matrix(y,nrow=1)))[,1] [,2] 1 1 34 2 2 5 3 3 6 4 4 NA 5 5 NA 6 6 NA Berend
Gabor Grothendieck
2012-Mar-15 12:55 UTC
[R] how to bind uneven column (not equal length) into matrix without recycling values
On Thu, Mar 15, 2012 at 5:08 AM, sagarnikam123 <sagarnikam123 at gmail.com> wrote:> i have >> x > [1] 1 2 3 4 5 6 >> y > [1] 34 ?5 ?6 >> z<-cbind(x,y) >> z > ? ? x ?y > [1,] 1 34 > [2,] 2 ?5 > [3,] 3 ?6 > [4,] 4 34 > [5,] 5 ?5 > [6,] 6 ?6 > > i don't want recycling, instead can we put NA /0 like below> z > ? ? x ?y > [1,] 1 34 > [2,] 2 ?5 > [3,] 3 ?6 > [4,] 4 ?NA > [5,] 5 ?NA > [6,] 6 ?NA > > & want distance matrix >ts does not recycle so try this: dist(cbind(x = ts(x), y = ts(y)), method = "max") If you need the intermediate two column structure then try cbind(x ts(x), y = ts(y)) as an mts series or t(t(cbind(x = ts(x), y ts(y)))) as a plain matrix. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com