On 2011-04-21 07:03, Marten Winter wrote:
Heja,
I hope someone is still there to help me:
How can I somehow merge/combine matrices to get such a result:
Matrix A
A B
x1 1 0
x2 1 1
Matrix B
C D
x3 1 0
x4 0 1
Resulting Matrix?
A B C D
x1 1 0 0 0
x2 1 1 0 0
x3 0 0 1 0
x4 0 0 0 1
If you d
A <- matrix(1:4, 2, 2, dimnames=list(c("x1","x2"), c("A","B")))
B <- matrix(5:8, 2, 2, dimnames=list(c("x3","x4"), c("C","D")))
result <- array(0, dim=dim(A)+dim(B),
dimnames=list(c(dimnames(A)[[1]], dimnames(B)[[1]]),
c(dimnames(A)[[2]], dimnames(B)[[2
Heja,
I hope someone is still there to help me:
How can I somehow merge/combine matrices to get such a result:
Matrix A
A B
x1 1 0
x2 1 1
Matrix B
C D
x3 1 0
x4 0 1
Resulting Matrix?
A B C D
x1 1 0 0 0
x2 1 1 0 0
x3 0 0 1 0
x4 0 0 0 1
Does anyone see this probably obvious solution with
Hi:
Try this:
lapply(results, function(x) array(unname(unlist(x)), c(3, 3, 2)))
HTH,
Dennis
On Wed, Jan 19, 2011 at 12:31 AM, Maas James Dr (MED) wrote:
> I get some results back from running an iterative analysis in the form of a
> list of matrices. What I would like to do with this list is
I get some results back from running an iterative analysis in the form of a
list of matrices. What I would like to do with this list is combine it such
that all the similar components get combined into a multidimensional array. If
possible I'd like to put results[[1]]$resultmean and results[[2
My prior solution was not correct.
If the idea is to combine each row of x with each row
of y then convert the matrices to data frames and
perform and outer join with SQL like this:
library(sqldf)
X <- as.data.frame(x)
Y <- as.data.frame(y)
as.matrix(sqldf("select * from X, Y", method = "raw"))
> -Original Message-
> From: Marc Schwartz [mailto:marc_schwa...@me.com]
> Sent: Monday, August 24, 2009 9:57 AM
> To: Daniel Nordlund
> Cc: r help
> Subject: Re: [R] Combining matrices
>
>
> On Aug 24, 2009, at 11:46 AM, Marc Schwartz wrote:
>
> &
Try this:
kronecker(cbind(x, y), rep(1, 3))
On Mon, Aug 24, 2009 at 12:16 PM, Daniel Nordlund wrote:
> If I have two matrices like
>
> x <- matrix(rep(c(1,2,3),3),3)
> y <- matrix(rep(c(4,5,6),3),3)
>
> How can I combine them to get ?
>
> 1 1 1 4 4 4
> 1 1 1 5 5 5
> 1 1 1 6 6 6
> 2 2 2 4 4 4
>
On Aug 24, 2009, at 11:46 AM, Marc Schwartz wrote:
On Aug 24, 2009, at 11:16 AM, Daniel Nordlund wrote:
If I have two matrices like
x <- matrix(rep(c(1,2,3),3),3)
y <- matrix(rep(c(4,5,6),3),3)
How can I combine them to get ?
1 1 1 4 4 4
1 1 1 5 5 5
1 1 1 6 6 6
2 2 2 4 4 4
2 2 2 5 5 5
2
On Aug 24, 2009, at 11:16 AM, Daniel Nordlund wrote:
If I have two matrices like
x <- matrix(rep(c(1,2,3),3),3)
y <- matrix(rep(c(4,5,6),3),3)
How can I combine them to get ?
1 1 1 4 4 4
1 1 1 5 5 5
1 1 1 6 6 6
2 2 2 4 4 4
2 2 2 5 5 5
2 2 2 6 6 6
3 3 3 4 4 4
3 3 3 5 5 5
3 3 3 6 6 6
The num
Try this;
do.call(rbind, lapply(split(x, seq(nrow(x))), cbind, y))
On Mon, Aug 24, 2009 at 1:16 PM, Daniel Nordlund wrote:
> If I have two matrices like
>
> x <- matrix(rep(c(1,2,3),3),3)
> y <- matrix(rep(c(4,5,6),3),3)
>
> How can I combine them to get ?
>
> 1 1 1 4 4 4
> 1 1 1 5 5 5
> 1 1 1
If I have two matrices like
x <- matrix(rep(c(1,2,3),3),3)
y <- matrix(rep(c(4,5,6),3),3)
How can I combine them to get ?
1 1 1 4 4 4
1 1 1 5 5 5
1 1 1 6 6 6
2 2 2 4 4 4
2 2 2 5 5 5
2 2 2 6 6 6
3 3 3 4 4 4
3 3 3 5 5 5
3 3 3 6 6 6
The number of rows and the actual numbers above are unimportant,
12 matches
Mail list logo