Search code examples
rstringradix

How to convert multiple characters (number identifiers) into a sequence separated by commas


My case is easy, I've seen several examples but all with the commas added separating the characters. I have 100 numbers to structure, I don't find useful write 100 commas

# I Want
c("50109018", "50109019", "50109025"...)

# I only paste 20
50109018
50109019
50109025
50109026
50109027
50118001
50202099
50203004
50203006
50203008
50203009
50203010
50203011
50203012
50203013
50203014
50203015
50203016
50203017
50203019
50203020
50203022
50203026
50203027
50203029
50203030
50203031
50203032


Solution

  • In order to keep the answer short, I am just using a few of your numbers, but just paste all of them into the text part.

    df = read.table(text="50109018
    50109019
    50109025
    50109026
    50109027")
    
    df
            V1
    1 50109018
    2 50109019
    3 50109025
    4 50109026
    5 50109027
    

    If you have the data in a text string, another way would be:

    text="50109018
    50109019
    50109025
    50109026
    50109027"
    
    unlist(strsplit(text, "\n"))