Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6773109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:37:41+00:00 2026-05-26T15:37:41+00:00

I am embrased to ask this simple question, but I could not figure it

  • 0

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:

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:37:42+00:00Added an answer on May 26, 2026 at 3:37 pm

    Use rep with the each argument to repeat each name. Then use paste to combine them with the suffix.

    paste(rep(names, each = 2), c("a", "b"), sep = "")
    

    Let’s look at that again in slow motion:

    suffixes <- c("a", "b")  # or letters[1:2] if you're feeling fancy
    n_suffixes <- length(suffixes)
    repeated_names <- rep(names, each = n_suffixes)
    final_names <- paste(repeated_names, suffixes, sep = "")
    

    Fancy alternate version using outer products:

    as.vector(t(outer(names, suffixes, paste, sep = "")))
    

    Though I think this is more for showing off, since it’s less readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I've done unit testing some, and have experience writing tests, but I have
I have strings like this: `(val1, val2, val3)` And I have ANTLR grammar to
This is probably the weakest, least technical question that stackoverflow has ever embraced. I
As I know Facebook has embraced Open ID but I can't find the url
Some of us still live in a programming environment where unit testing has not
I am in the process of building a large asp.net Mvc project and have
Following the way Rob does it, I have the classes that are generated by
I have a vCard file containing thousands of contacts. In a vCard file contacts
So I have a problem. Or rather my friend has a problem, since I
I have a Python function which receives numerous variables, and builds an SQL query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.