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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:59:22+00:00 2026-05-23T23:59:22+00:00

I am trying to extract numeric data from a database where the columns have

  • 0

I am trying to extract numeric data from a database where the columns have been set as VARCHAR(100). All data in the relevant columns are numeric so there shouldn’t be any problem extracting the data formatted as integer. Is there a nice way to do this in R?

Here is what I got:

m_df <- dbGetQuery(conn, paste("SELECT ", direc, " as Position, ", power, " as Power FROM ", table, 
                     " d LEFT JOIN files f on f.id=d.fileid WHERE parc='", parc, 
                     "' AND timestamp >= '", w_date[1], "' and timestamp <= '", w_date[2], 
                     "' AND plantnumber = ", w_mach, sep=""))

Executing the following:

sum(m_df$Power)

Produces this error:

Error in sum(m_df$Power) : invalid 'type' (character) of argument

Performing:

str(m_df)

Generates:

 'data.frame':   4317 obs. of  2 variables:
 $ Position: chr  "280" "281" "288" "294" ...
 $ Power   : chr  "294" "342" "324" "284" ...
  • 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-23T23:59:22+00:00Added an answer on May 23, 2026 at 11:59 pm

    You are trying to sum some characters and R is saying “WHAAAA?”. The little snippet that follows reproduces your error.

    (x.char <- sum(c("1", "2", "3")))
     Error in sum(c("1", "2", "3")) : invalid 'type' (character) of argument
    (sum(as.numeric(x.char)))
     [1] 6
    

    Run as.numeric function on your data.frame and you’re good to go.

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

Sidebar

Related Questions

I am trying to extract duplicate rows from my database. I have a listings
I am trying to extract data from this String: Hello there. Blah blahblah blah
I'm trying to extract all matches from a EBML definition, which is something like
I'm trying to extract monetary sums stored in some poorly formated xml columns (there
I'm trying extract the nth + 1 and nth + 3 columns from a
I am trying to capture / extract numeric values from some strings. Here is
While trying to extract data from a view by joining it with two other
I am trying to extract some data from XML but when I execute the
I am trying to extract all class names from my solution in C3 vs
I am trying to extract blocks of JSON data from a data stream in

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.