Create repeating line vector with suffix extension

I would like to create a vector based on the repetition of the string "FST", but with a number at the end that increments:

"Fst1" "Fst2" "Fst3" "Fst4" ... "Fst100" 
+6
source share
2 answers

An alternative to paste is sprintf , which can be a little more convenient if, for example, you wanted to "fill" your numbers with leading zeros.

Here is an example:

 sprintf("Fst%d", 1:10) ## No padding # [1] "Fst1" "Fst2" "Fst3" "Fst4" "Fst5" # [6] "Fst6" "Fst7" "Fst8" "Fst9" "Fst10" sprintf("Fst%02d", 1:10) ## Pads anything less than two digits with zero # [1] "Fst01" "Fst02" "Fst03" "Fst04" "Fst05" # [6] "Fst06" "Fst07" "Fst08" "Fst09" "Fst10" 

So for your question, you would look:

 sprintf("Fst%d", 1:100) ## or sprintf("Fst%03d", 1:100) 
+10
source

You can use the insert function to create a vector that combines the given character string with extension numbers: paste0('Fst', 1:100)

+2
source

Source: https://habr.com/ru/post/1204162/


All Articles