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

  • Home
  • SEARCH
  • 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 7925155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:09:36+00:00 2026-06-03T18:09:36+00:00

I have a data frame composed of numeric and non-numeric columns. I would like

  • 0

I have a data frame composed of numeric and non-numeric columns.

I would like to extract (subset) only the non-numeric columns, so the character ones. While I was able to subset the numeric columns using the string: sub_num = x[sapply(x, is.numeric)], I’m not able to do the opposite using the is.character form. Can anyone help me?

  • 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-03T18:09:37+00:00Added an answer on June 3, 2026 at 6:09 pm

    Ok, I did a short try about my idea.

    I could confirm that the following code snippet is working:

    str(d)
     'data.frame':  5 obs. of  3 variables:
      $ a: int  1 2 3 4 5
      $ b: chr  "a" "a" "a" "a" ...
      $ c: Factor w/ 1 level "b": 1 1 1 1 1
    
    
    # Get all character columns
    d[, sapply(d, class) == 'character']
    
    # Or, for factors, which might be likely:
    d[, sapply(d, class) == 'factor']
    
    # If you want to get both factors and characters use
    d[, sapply(d, class) %in% c('character', 'factor')]
    

    Using the correct class, your sapply-approach should work as well, at least as long as you insert the missing , before the sapply function.

    The approach using !is.numeric does not scale very well if you have classes that do not belong in the group numeric, factor, character (one I use very often is POSIXct, for example)

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

Sidebar

Related Questions

I have a data frame and I would like to impute missing values based
I have a data frame with two columns: an ID and some numeric value
I have a data frame with three columns and I'd like to make a
I have a data frame that looks like this, with two key columns and
I have a data.frame with 2 columns: Node A, Node B. Each entry in
I have a data frame with two columns. First column contains categories such as
I have a data frame with gaps like this: Var1 Var2 Var3 1 NA
I have a data.frame in R that looks like this: score rms template aln_id
I have a data frame of integers that is a subset of all of
I have a data.frame , called so_data. Columns 13:23 are list s, which hold

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.