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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:23:21+00:00 2026-06-14T08:23:21+00:00

I extracted a mixed variable which includes both numeric and string values from a

  • 0

I extracted a mixed variable which includes both numeric and string values from a data file using strsplit function. I ended up with a variable just as seen below:

> sample3

[[1]]
[1] "1200" "A"  

[[2]]
[1] "1193" "A"  

[[3]]
[1] "1117" "B"  

[[4]]
[1] "5663" 

[[5]]
[1] "7003" "C" 

[[6]]
[1] "1205" "A"  

[[7]]
[1] "2100" "D"  

[[8]]
[1] "1000" "D"  

[[9]]
[1]  "D" 

[[10]]
[1] "1000" "B"

I need to split this into two variables/vectors(or convert to a two-columned matrix). I tried to use unlist(sample3) code then put the all values into a matrix with ncol=2 however since there are some missing data points the result is not correct when I use this way. I think I need to solve missing data issue before putting into a two columned matrix. Does anyone have any idea on this issue? Any help will be greatly appreciated.

  • 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-14T08:23:22+00:00Added an answer on June 14, 2026 at 8:23 am

    Something like this will work

    # dummy data
    x <- list(c('100','a'), '100', c('a'), c('1000','b'))
    
    numeric_x <- unlist(lapply(x,function(x) {.x <- head(x,1); as.numeric(.x)}))
    
    character_x <- unlist(lapply(x,function(x) {.x <- tail(x,1); if(is.na(as.numeric(.x))) {return(.x)} else {return(NA)}}))
    

    There will be a much nicer regex answer I am sure

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

Sidebar

Related Questions

I am trying to use data extracted from a XML file by getElementByTagName and
I have just Extracted the cells from the excel sheet using Apache POI, everything
I have extracted the following code from selenium IDE.(c# remote control) using System; using
Here's the code (extracted from an existing application): CURL *curl = curl_easy_init(); _ASSERTE(curl); string
I have an NSArray that is extracted from core data. The entities in the
I've extracted the setting names and their respective values out of a configuration file
I have extracted data to a data frame with mixed format dates that need
I want to parse data which might contain mixed patterns like 1-4pm 1pm-5pm noon
I received an Excel file that references some data from a MDB file. When
History: Extracted raster data from the static Google map png, loaded it on the

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.