Re: [R] Merging matrices of different rows

2025-06-29 Thread Steven Yen
I understand. Thanks. My NA rows are to follow the end of the shorter matrix, to make the two matrices same depth (number of rows), as in Garbor’s demonstration: [,1] [,2] [,3] [,4] [1,]1759 [2,]286 10 [3,]397 11 [4,]4 108 12 [5,

Re: [R] Merging matrices of different rows

2025-06-29 Thread Gabor Grothendieck
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 wrote: > > Thanks to all. In my application I can always arrange to have the shorter > matrix come second which is to

Re: [R] Merging matrices of different rows

2025-06-29 Thread Steven Yen
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 2

Re: [R] Merging matrices of different rows

2025-06-29 Thread Jeff Newmiller via R-help
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 NA

Re: [R] Merging matrices of different rows

2025-06-29 Thread Gabor Grothendieck
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,]1759 [2,]286 10 [3,]397 11 [4,]4 108

Re: [R] Merging matrices of different rows

2025-06-26 Thread Ben Bolker
There's always cbind.fill <- function(...) { L <- list(...) tmats <- lapply(L, \(x) as.data.frame(t(x))) t(do.call(plyr::rbind.fill, tmats)) } * rbind.fill is in plyr, not dplyr * apparently rbind.fill needs data frames as input * this function isn't very efficient, but might be good

Re: [R] Merging matrices of different rows

2025-06-26 Thread Steven Yen
Thanks. I will program my own cbind.fill. Steven from iPhone > On Jun 26, 2025, at 7:11 PM, Rui Barradas wrote: > > Às 11:46 de 26/06/2025, Steven Yen escreveu: >> I'd like to cbind matrices of different number of rows, with missing values >> filled by "NA". I used dplyr. The following is obv

Re: [R] Merging matrices of different rows

2025-06-26 Thread Rui Barradas
Às 11:46 de 26/06/2025, Steven Yen escreveu: 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,]17 [2,]2

[R] Merging matrices of different rows

2025-06-26 Thread Steven Yen
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,]17 [2,]28 [3,]39 [4,]4 10 [5,]5

Re: [R] merging matrices

2013-10-21 Thread PIKAL Petr
Behalf Of jim holtman > Sent: Monday, October 21, 2013 5:21 PM > To: Mohammad Goodarzi > Cc: R mailing list > Subject: Re: [R] merging matrices > > ?list.files > ?read.table > ?rbind > > Jim Holtman > Data Munger Guru > > What is the problem that you are try

Re: [R] merging matrices

2013-10-21 Thread Carl Witthoft
If you have over a thousand files on your desktop, you have bigger problems than just how to load them into R. Where do these files come from, and why do you want to "merge" them into a single entity? -- View this message in context: http://r.789695.n4.nabble.com/merging-matrices-tp4678702p

Re: [R] merging matrices

2013-10-21 Thread jim holtman
?list.files ?read.table ?rbind Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On Mon, Oct 21, 2013 at 6:18 AM, Mohammad Goodarzi wrote: > Dear all, > > I have to load more than 1000 matrices from desktop wh

Re: [R] merging matrices

2013-10-21 Thread Bert Gunter
Have you read "An Introduction to R" (ships with R) or any R web tutorials to learn how R works? If not, don't you think you should before posting here? Your question appears to be rather basic. Cheers, Bert On Mon, Oct 21, 2013 at 3:18 AM, Mohammad Goodarzi wrote: > Dear all, > > I have to load

[R] merging matrices

2013-10-21 Thread Mohammad Goodarzi
Dear all, I have to load more than 1000 matrices from desktop which all of them have the same size. If I do it manually, it would be very hard, can you please guide me how to load them and merge them together ? for example I want to put them one after another X1 X2 X3 etc Many thanks, Mohammad

Re: [R] Merging Matrices

2010-03-20 Thread Gabor Grothendieck
Actually both the solutions I listed assume that every row in small is in big. Although that was the case in the example you displayed, If that is not the case in general then use intersect: ix <- intersect(rownames(big), rownames(small)) result <- big result[ix, ix] <- big[ix, ix] + small[ix, ix

Re: [R] Merging Matrices

2010-03-20 Thread Gabor Grothendieck
The original post said the matrices are symmetric but it seems from the examples that they are not symmetric but do each have the same row and column names so we have assumed only this latter condition instead. If your matrices are called big and small then: ix <- rownames(big) %in% rownames(smal

Re: [R] Merging Matrices

2010-03-20 Thread duncandonutz
To clarify, the two matrices might look like this: A B C D E F A 1 2 3 4 5 6 B 2 4 6 8 10 12 C 0 0 0 0 0 0 D 0 1 0 1 0 1 E 3 6 9 11 13 15 F 2 2 2 2 2 2 B D E B 4 9 13 D 9 8 7 E 1 0 1 I would like this: A B C D E

Re: [R] Merging Matrices

2010-03-19 Thread Steven McKinney
> From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf > Of duncandonutz [dwads...@unm.edu] > Sent: March 19, 2010 1:11 PM > To: r-help@r-project.org > Subject: [R] Merging Matrices > > I have two symme

Re: [R] Merging Matrices

2010-03-19 Thread David Winsemius
On Mar 19, 2010, at 4:11 PM, duncandonutz wrote: I have two symmetric matrices, but of different dimensions. The entries are identified by specific labels some of which are shared by both matrices. I would like to sum the two matrices, but retain the union of the two. In other words,

[R] Merging Matrices

2010-03-19 Thread duncandonutz
I have two symmetric matrices, but of different dimensions. The entries are identified by specific labels some of which are shared by both matrices. I would like to sum the two matrices, but retain the union of the two. In other words, I want the result to be the same size as the larger of the