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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:47:53+00:00 2026-06-18T07:47:53+00:00

I have a problem. Say I have a vector x: x : [1] 2

  • 0

I have a problem. Say I have a vector x:

x:

 [1] "2 416" "143"   "280"   "2 503" "144"   "128"   "55"    "697"   "826"   "9"     "35"    "9 257" "234"   "2 044" NA      "219"  
[17] NA      NA      "219"   "7 431" "82"    "88"    "186"   "231"   "192"   "456"   "585"   "75"    "142"   NA      NA      NA     
[33] "72"    "246"   "900"   "143"   "231"   "195"   "282"   "226"   "967"   "247"   "2 252" "694"   "64"    "7 744" "204"   "428"  
[49] "19"    "94"    "174"   "292"   "94"    "172"   "221"   "123"   "404"   "385"   "324"   "346"   "658"   "53"    "377"   "119"  
[65] NA      "51"    "391"   "1 072" "387"   "1 742" "518"   "173"   "366"   "67"    "163"   "1 151" "382"   "864"   "184"   "172"  
[81] NA      "538"   "39"    "2 272" "334"   "464"   "82"    "112" 

class(x) 
"character" 

I imported this vector from Excel

x=read.csv(file="C:/Users/Documents/x.csv",header=TRUE,sep=";",na.strings=c("NA",""),
dec = ",",stringsAsFactors=FALSE,blank.lines.skip = F)

No when I try to convert x to numeric, this happens:

as.numeric(x)

 [1]  NA 143 280  NA 144 128  55 697 826   9  35  NA 234  NA  NA 219  NA  NA 219  NA  82  88 186 231 192 456 585  75 142  NA  NA  NA  72
[34] 246 900 143 231 195 282 226 967 247  NA 694  64  NA 204 428  19  94 174 292  94 172 221 123 404 385 324 346 658  53 377 119  NA  51
[67] 391  NA 387  NA 518 173 366  67 163  NA 382 864 184 172  NA 538  39  NA 334 464  82 112
Warning message:
NAs introduced by coercion 

So some numbers, i.e. “2 416” is converted to NA, while I want the number to be converted to 2 416. I want R to interpret "2 416" as a numeric value 2416What am I doing wrong?

Best Regards

  • 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-18T07:47:54+00:00Added an answer on June 18, 2026 at 7:47 am

    You have to replace the spaces with empty strings before doing the conversion:

    x <- c("2 416", "143", "280", "2 503")
    

    Immediate conversion fails, because “2 416” isn’t a number:

    as.numeric(x)
    [1]  NA 143 280  NA
    Warning message:
    NAs introduced by coercion 
    

    Use gsub() to replace spaces with empty strings, then convert:

    as.numeric(gsub(" ", "", x))
    [1] 2416  143  280 2503
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have problem use link_to_remote link_to_remote document example say link_to_remote Delete this post, :update
Problem : I have say 4 activities A, B, C and D. A --
I have this problem where after a field (say Field3 in table MyTable) is
I have a problem with my path. Say I have a PHP file in
I have a problem with the Microsoft EnterpriseLibrary validation framework. Let's say we have
I have a problem that I can't resolve. Let's say I have this map
The problem: let's say I have two tables Client , and Product , in
The underlying problem - let's say my documents have categories and timestamps . If
Here is my problem: I have an array of model class(Let's say, 'addressModel' with
A toy-case for my problem: I have a numpy array of size, say, 1000:

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.