Thank you. Using ‘each’ is shorter code, so better if the requested order was 
important versus being an initial solution.

blocC <- c(rep(x=c(1:13), times=84)) #it makes 84 copies of the numbers 1:13
blocC <- arrange(.data = data.frame(blocC), blocC) #sort to get requested order.

blocD <- c(rep(x=c(1:13), each=84)) #it makes 84 copies of 1, then 84 copies of 
2 …
blocD <- data.frame(blocC=blocD) #give the column the same name.
identical(blocC, blocD)
all.equal(blocC, blocD)

and both identical() and all.equal() return TRUE. Either way gives the same end 
product.

Tim

From: Bert Gunter <bgunter.4...@gmail.com>
Sent: Thursday, June 13, 2024 9:13 PM
To: Ebert,Timothy Aaron <teb...@ufl.edu>
Cc: Francesca PANCOTTO <francesca.panco...@unimore.it>; r-help@r-project.org
Subject: Re: [R] Create a numeric series in an efficient way

[External Email]
Nope. She would have wanted the 'each' argument = 84. See ?rep.

-- Bert



On Thu, Jun 13, 2024 at 3:54 PM Ebert,Timothy Aaron 
<teb...@ufl.edu<mailto:teb...@ufl.edu>> wrote:
Maybe this was your solution?

blocC <- c(rep(x=c(1:13), times=84))
blocC <- arrange(.data = data.frame(blocC), blocC)

The second line sorts, but that may not be needed depending on application. The 
object class is also different in the sorted solution.

Tim
-----Original Message-----
From: R-help 
<r-help-boun...@r-project.org<mailto:r-help-boun...@r-project.org>> On Behalf 
Of Francesca PANCOTTO via R-help
Sent: Thursday, June 13, 2024 2:22 PM
To: r-help@r-project.org<mailto:r-help@r-project.org>
Subject: Re: [R] Create a numeric series in an efficient way

[External Email]

I apologize, I solved the problem, sorry for that.
f.



Il giorno gio 13 giu 2024 alle ore 16:42 Francesca PANCOTTO < 
francesca.panco...@unimore.it<mailto:francesca.panco...@unimore.it>> ha scritto:

> Dear Contributors
> I am trying to create a numeric series with repeated numbers, not
> difficult task, but I do not seem to find an efficient way.
>
> This is my solution
>
> blocB <- c(rep(x = 1, times = 84), rep(x = 2, times = 84), rep(x = 3,
> times = 84), rep(x = 4, times = 84), rep(x = 5, times = 84), rep(x =
> 6, times = 84), rep(x = 7, times = 84), rep(x = 8, times = 84), rep(x
> = 9, times = 84), rep(x = 10, times = 84), rep(x = 11, times = 84),
> rep(x = 12, times = 84), rep(x = 13, times = 84))
>
> which works but it is super silly and I need to create different
> variables similar to this, changing the value of the repetition, 84 in this 
> case.
> Thanks for any help.
>
>
> F.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org<mailto:R-help@r-project.org> mailing list -- To 
UNSUBSCRIBE and more, see
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<mailto:R-help@r-project.org> mailing list -- To 
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to