Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to entry repeated value in a row

Please pardon me for such silly question.

If I want to build a try as this: 2 "", "Try1", n-1 "", "Try2", n-1 "", which n is number of elements in Level.


level <- c("L1", "L2", "L3", "L4")
try<- t(c("","", "Try1" ,"","","", "Try2","","", ""))

Is it a way to build try in a way like 2"", "Try1", (length(level)-1)"", "Try2", (length(level)-1)""?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

We may use

n <- length(Level) - 1
tail(na.omit(c(mapply(`c`, replicate(n, rep("", n), 
   simplify = FALSE), c(paste0("Try", 1:2), NA)))), -1)
[1] ""     ""     "Try1" ""     ""     ""     "Try2" ""     ""     ""    
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading