I am embrased to ask this simple question, but I could not figure it out.
I have a variable
names <- c("M1", "K2L", "C2L", "N", "R_1_2", "CLA", "T123") # the real dataset has > 6000 valriables
I want to double names and add alphabets “a” and “b” and the output (consider order too) would look like the following:
M1a, M1b, K2La, K2Lb, C2La, C2Lb, Na, Nb, R_1_2a, R_1_2b, CLAa, CLAb, T123a, T123b
Thanks for the help:
Use
repwith theeachargument to repeat each name. Then usepasteto combine them with the suffix.Let’s look at that again in slow motion:
Fancy alternate version using outer products:
Though I think this is more for showing off, since it’s less readable.