You don't have to arrange that the shorter one comes second. The cbind.ts approach works whether the shorter one is first or second.
On Sun, Jun 29, 2025 at 12:14 PM Steven Yen <st...@ntu.edu.tw> wrote: > > Thanks to all. In my application I can always arrange to have the shorter > matrix come second which is to be filled with NA. I Will try the ts approach. > Words work less effectively for me. This could have work if plain R can be > more accommodating in cbind. Thanks. > > Steven from iPhone > > > On Jun 29, 2025, at 11:03 PM, Jeff Newmiller <jdnew...@dcn.davis.ca.us> > > wrote: > > > > This capability that ts objects have seems ill-advised. There is always a > > meaning associated with which row and column a matrix has, and this assumes > > that the shorter dimension is associated with times corresponding to the > > first rows of the longer matrix. In general you don't know whether the NAs > > should be at the beginning or whether there are missing rows in the middle, > > or even whether the time intervals don't overlap at all or are on different > > intervals. IMO there should be a separate step required before cbind that > > resolves these questions and appropriately extends the dimension rather > > than embedding this particular resolution approach into the cbind function. > > It could be as simple as an "extend Rows" function... as long as it is > > explicit in the calling code where this strategy can more easily be > > identified, debated, and fixed. > > > >> On June 29, 2025 4:56:23 AM PDT, Gabor Grothendieck > >> <ggrothendi...@gmail.com> wrote: > >> cbind does work on differently shaped ts objects so: > >> > >> a <- matrix(1:12,nrow=6) > >> b <- matrix(5:12,nrow=4) > >> > >> tmp <- cbind(ts(a), ts(b)) > >> array(tmp, dim(tmp)) > >> > >> giving > >> > >> [,1] [,2] [,3] [,4] > >> [1,] 1 7 5 9 > >> [2,] 2 8 6 10 > >> [3,] 3 9 7 11 > >> [4,] 4 10 8 12 > >> [5,] 5 11 NA NA > >> > >>> On Thu, Jun 26, 2025 at 6:47 AM Steven Yen <st...@ntu.edu.tw> wrote: > >>> > >>> I'd like to cbind matrices of different number of rows, with missing > >>> values filled by "NA". I used dplyr. The following is obviously not > >>> working. Help appreciated. > >>> > >>>> library(dplyr) > >>>> a<-matrix(1:12,nrow=6); a > >>> [,1] [,2] > >>> [1,] 1 7 > >>> [2,] 2 8 > >>> [3,] 3 9 > >>> [4,] 4 10 > >>> [5,] 5 11 > >>> [6,] 6 12 > >>>> b<-matrix(5:12,nrow=4); b > >>> [,1] [,2] > >>> [1,] 5 9 > >>> [2,] 6 10 > >>> [3,] 7 11 > >>> [4,] 8 12 > >>>> cbind.fill(a,b) > >>> Error in cbind.fill(a, b) : could not find function "cbind.fill" > >>> > >>> Steven from iPhone > >>> [[alternative HTML version deleted]] > >>> > >>> ______________________________________________ > >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > >>> https://stat.ethz.ch/mailman/listinfo/r-help > >>> PLEASE do read the posting guide > >>> https://www.R-project.org/posting-guide.html > >>> and provide commented, minimal, self-contained, reproducible code. > >> > >> > >> > > > > -- > > Sent from my phone. Please excuse my brevity. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide https://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.