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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:53:40+00:00 2026-05-23T15:53:40+00:00

I have a a variable in a dataframe whose observations are a mix of

  • 0

I have a a variable in a dataframe whose observations are a mix of numeric and character values (due to faulty data entry). How can I subset in only the observations which are numeric? Suppose the values of filename$varname are (1, 2, 1, 5, 3, a, 3, d, 1), I would like subset out “a” and “d” and keep only the rest of the values which are numeric.

  • 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-23T15:53:41+00:00Added an answer on May 23, 2026 at 3:53 pm

    Without a reproducible example it is hard to see what your data actually looks like. For instance, is the column of your data frame a factor or just strings? If it is just strings then Andrie’s answer works (just use as.numeric()), and if the data is a factor you first need to convert that to strings with as.character(x):

    as.numeric(as.character(filename$varname))
    

    You will get some NAs but that is absolutely fine as those values are indeed missing.

    EDIT: To clarify abit more. You have a data frame, so you don’t want to take values out of the data frame as then it wouldn’t be a dataframe anymore (equal rows). You want to correctly assign NA for missing values instead as most statistical functions in R can handle them.

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

Sidebar

Related Questions

A categorical variable V1 in a data frame D1 can have values represented by
I have a several data sets with 75,000 observations and a type variable that
I have the following variable and dataframe welltypes <- c(LC,HC) qccast <- data.frame( LC_mean=1:10,
I have variable @count of datatype int.I am setting values to this @count. I
How I can have variable number of parameters in my function in C++. Analog
I have very large dataframe and I need to choose variable number satisfying certain
I have some data in a dataframe calvarbyruno.1 with variables Nominal and PAR that
i have a data frame with 2 groups 1 timevariable and an dependent variable.
I have an unbalanced quarterly panel data set with missing values. I want to
Let's say I have a data frame, like this: df <- data.frame( variable =

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.