# Repeat matrices

2 messages
Open this post in threaded view
|

## Repeat matrices

 Dear r-users, I have a set of numbers that I would like to repeat for let say 10 times and each number is repeated by vertically. I tried this: a <-  c(5.78, 5.79,5.86) tran_a <- t(matrix(rep.int(a, 10),3)) dput(tran_a) structure(c(5.78, 5.78, 5.78, 5.78, 5.78, 5.78, 5.78, 5.78, 5.78, 5.78, 5.79, 5.79, 5.79, 5.79, 5.79, 5.79, 5.79, 5.79, 5.79, 5.79, 5.86, 5.86, 5.86, 5.86, 5.86, 5.86, 5.86, 5.86, 5.86, 5.86), .Dim = c(10L, 3L)) Or is there any smarter way? Best regards, -- *Dr. Roslinazairimah Binti Zakaria* *Tel: +609-5492370; Fax. No.+609-5492766* *Email: [hidden email] <[hidden email]>; [hidden email] <[hidden email]>* Deputy Dean (Academic & Student Affairs) Faculty of Industrial Sciences & Technology University Malaysia Pahang Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Repeat matrices

 Not sure it would be any smarter, but what about: a <- c(5.78, 5.79,5.86) n <- 10 matrix(rep(a,each=n), nrow=n) That way, it would be easy to build a function with 'a' and 'n' as arguments. HTH, Ivan -- Ivan Calandra, PhD Scientific Mediator University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 [hidden email] -- https://www.researchgate.net/profile/Ivan_Calandrahttps://publons.com/author/705639/Le 01/08/2016 à 11:27, roslinazairimah zakaria a écrit : > Dear r-users, > > I have a set of numbers that I would like to repeat for let say 10 times > and each number is repeated by vertically. > > I tried this: > > a <-  c(5.78, 5.79,5.86) > tran_a <- t(matrix(rep.int(a, 10),3)) > dput(tran_a) > > structure(c(5.78, 5.78, 5.78, 5.78, 5.78, 5.78, 5.78, 5.78, 5.78, > 5.78, 5.79, 5.79, 5.79, 5.79, 5.79, 5.79, 5.79, 5.79, 5.79, 5.79, > 5.86, 5.86, 5.86, 5.86, 5.86, 5.86, 5.86, 5.86, 5.86, 5.86), .Dim = c(10L, > 3L)) > > Or is there any smarter way? > > Best regards, ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.