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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:41:57+00:00 2026-06-15T12:41:57+00:00

Suppose I have a data.frame that’s completely numeric . If I make one entry

  • 0

Suppose I have a data.frame that’s completely numeric. If I make one entry of the first column a character (for example), then the entire first column will become character.

Question: How do I reverse this. That is, how do I make it such that any character objects inside the data.frame that are “obviously” numeric objects are forced to be numeric?

MWE:

test <- data.frame(matrix(rnorm(50),10))
is(test[3,1])
test[1,1] <- "TEST"
is(test[3,1])
print(test)

So my goal here would be to go FROM the way that test is now, TO a state of affairs where test[2:10] is numeric. So I guess I’m asking for a function that does this over an entire data.frame.

  • 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-15T12:41:58+00:00Added an answer on June 15, 2026 at 12:41 pm

    Short answer is you cannot.
    As was mentioned in the comments, in a data frame, all elements of a column must have the same mode.

    If you would like to specifically find the values that are “number like” you can use the following (where vec here would be, say, a data frame column)

      vec[!is.na(as.numeric((vec)))]
    

    You can then convert these, but unfortunately you cannot put the converted values back into the same column. As as you do, they will be coerced back to character


    As for a function that can convert the whole dataframe to numeric (realizing that isolating specific entries as exceptions is not possible), you can use sapply

      sapply(dataFrameName, as.numeric)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a dataframe like this one: df <- data.frame (id = c(a,
Suppose I have a data frame, df, that looks like: f t1 t2 t3
Suppose that you have a data frame with many rows and many columns. The
Suppose I have a data.frame with N rows. The id column has 10 unique
I have a data frame with several columns; some numeric and some character. How
Suppose I have a data frame in R that has names of students in
Suppose that we have a data frame that looks like set.seed(7302012) county <- rep(letters[1:4],
I have a data.frame, d1, that has 7 columns, the 5th through 7th column
Suppose I have a dataset: test = data.frame(x=c(1:11), y=as.character(c(1:11))) where the collumn 'y' is
Suppose I have an R data frame with columns that specify location (lat/long), height,

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.