Only vectors recycle. If you don't want the behaviour if the matrix to reflect
that of the underlying vector then don't use recycling. Instead use indexing.
M.1 <- M.2[rep(1:5,3),]
---
Jeff NewmillerTh
library(plyr)
M.1[,1:2]<-do.call(rbind,alply(replicate(3,M.2),3,function(x) x))
#or
M.1[,1:2]<-matrix(aperm(replicate(3,M.2),c(1,3,2)),ncol=2)
A.K.
- Original Message -
From: Thiem Alrik
To: "mailman, r-help"
Cc:
Sent: Sunday, July 14, 2013 9:48 AM
Subject: [R] Ma
Dear list,
I have a matrix M.1 (30x2) into which I would like to paste another matrix M.2
(10x2) three times. However, the columns get flipped in every odd-numbered
recycle run. How can I avoid this behavior?
M.1 <- matrix(numeric(30*2), ncol = 2)
M.2 <- t(combn(1:5, 2))
M.1[, 1:2] <- M.2
Many
3 matches
Mail list logo