[R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n
Rmh
rmh at temple.edu
Mon Apr 20 02:50:20 CEST 2015
- Previous message: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n
- Next message: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
rep(1:n, each=4)
Sent from my iPhone
> On Apr 19, 2015, at 09:44, John Sorkin <JSorkin at grecc.umaryland.edu> wrote:
>
> Windows 7 64-bit
> R 3.1.3
> RStudio 0.98.1103
>
>
> I am trying to generate a list of length 4n which consists of the integers 1 to n repeated in groups of four, i.e.
>
> 1,1,1,1, 2,2,2,2, 3,3,3,3, . . . . , n,n,n,n
>
> (The spaces in the list are added only for clarity.)
>
> I can generate the list as follows, but the code must be modified for any value n, and the code is UGLY!
>
> c(rep(1,4), rep(2,4), rep(3,4), . . . ,c(n,4))
>
> Can anyone help me?
>
> Thank you,
> John
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
>
> Call
> Send SMS
> Add to Skype
> You'll need Skype CreditFree via Skype
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
>
>
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:12}}
- Previous message: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n
- Next message: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the R-help
mailing list