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 8234019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:20:12+00:00 2026-06-07T18:20:12+00:00

I have a string in some text of the form 12,34,77 , including the

  • 0

I have a string in some text of the form "12,34,77", including the quotation marks.

I need to get the values of each of those numbers into a list. I tried using lapply and strsplit:

control2=lapply(strsplit(data$values,","),as.numeric)

but I get the error:

non character argument

What am I doing wrong?

  • 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-06-07T18:20:15+00:00Added an answer on June 7, 2026 at 6:20 pm

    1) strapply

    1a) scalar Here is a one-liner using strapply from the gsubfn package:

    library(gsubfn)
    x <- '"12,34,567"'
    
    strapply(x, "\\d+", as.numeric, simplify = c)
    ## [1]  12  34 567
    

    1b) vectorized A vectorized version is even simpler — just remove the simplify=c like this:

    v <- c('"1,2,3"', '"8,9"') # test data
    strapply(v, "\\d+", as.numeric)`
    

    2) gsub and scan

    2a) scalar and here is a one-linear using gsub and scan:

    scan(text = gsub('"', '', x), what = 0, sep = ",")
    ## Read 3 items
    ## [1]  12  34 567
    

    2b) vectorized A vectorized version would involve lapply-ing over the components:

    lapply(v, function(x) scan(text = gsub('"', '', x), what = 0, sep = ","))
    

    3) strsplit

    3a) scalar and here is a strsplit solution. Note that we split on both " and , :

    as.numeric(strsplit(x, '[",]')[[1]][-1])
    ## [1]  12  34 567
    

    3b) vectorized A vectorized solution would, again, involve lapply-ing over the components:

    lapply(v, function(x) as.numeric(strsplit(x, '[",]')[[1]][-1]))
    

    3c) vectorized – simpler or slightly simpler:

    lapply(strsplit(gsub('"', '', v), split = ","), as.numeric)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string: 'This is some random text so you don't get upset
Okay, I have this textfield form that contains some text. What I need to
I have a string: [\n['-','some text what\rcontains\nnewlines'],\n\n trying to parse: Regex.Split(@[\n['-','some text what contains
I have a string like: hello #this# is #some text string# text text I
i have a string like this one: $string = some text http://dvz.local/index/index/regionId/28 http://stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.php
I have a String as follows 2012-06-29 Some text 2012-06-30 Some text .. I
I have a string like this: |T1| This is some text for the first
i have a string that contain some html in string form, like this one
I have several strings in the rough form: [some text] [some number] [some more
I have some content that contains a token string in the form $string_text =

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.