Home > database >  How to create a vector with character string and corresponding number for each repeat
How to create a vector with character string and corresponding number for each repeat

Time:05-01

Hi I am trying to create a vector which has this information user_1, through user_33 so that I can easily copy and paste this information into a .y purrr function. I was looking at using rep(user_, [1:33]) but do not understand the syntax of how to create the output I am looking for. Thank you

CodePudding user response:

Use paste or paste0. The second argument is vectorized, so it'll give you the full vector.

paste("user", 1:33, sep = "_")
paste0("user_", 1:33)

output

 [1] "user_1"  "user_2"  "user_3"  "user_4"  "user_5"  "user_6"  "user_7"  "user_8" 
 [9] "user_9"  "user_10" "user_11" "user_12" "user_13" "user_14" "user_15" "user_16"
[17] "user_17" "user_18" "user_19" "user_20" "user_21" "user_22" "user_23" "user_24"
[25] "user_25" "user_26" "user_27" "user_28" "user_29" "user_30" "user_31" "user_32"
[33] "user_33"
  • Related