Ben Bolker wrote:
Dimitris Rizopoulos <d.rizopoulos <at> erasmusmc.nl> writes:
you can use indexing, e.g.,
mat <- matrix(rnorm(20), 4, 5)
mat
mat[rep(1:nrow(mat), 3), ]
I hope it helps.
Best,
Dimitris
or matrix trickery:
z <- as.data.frame(matrix(sample(1:9,20,replace=TRUE),nrow=4))
matrix(rep(as.matrix(z),3),ncol=ncol(z),byrow=TRUE)
I do sometimes wish there were a more generic Rep() defined as
Rep <- function(x,n) {
result <- list()
for (i in 1:n) {
result[[i]] <- x
}
result
}
then one could say do.call("rbind",Rep(x,3))
You mean like:
do.call('rbind', rep(list(x), 3))
Patrick Burns
patr...@burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.