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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:18:31+00:00 2026-05-29T10:18:31+00:00

I am looking to remove multiple observations from one column within a dataframe based

  • 0

I am looking to remove multiple observations from one column within a dataframe based on their value without affecting the rest of the row.

df1=data.frame(c("male","female","male"),seq(1,30),seq(11,40))
names(df1) = c("col_a","col_b","col_c")

For example removing the values from column b that are below 5 or above 20 without affecting columns a or c. I am then looking to use this data for descriptive analysis and summaries.

Currently I am using this code to do the job:

df1$col_b[df1$col_b<5|df1$col_b>20] <- ""
df1$col_b<-as.numeric(df1$col_b)

However this creates NA values which get in the way of the analysis. Is there a way of doing this that does not create NA values or a quick way of removing them without affecting the row?

  • 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-29T10:18:32+00:00Added an answer on May 29, 2026 at 10:18 am

    A numeric column can have normal values, NA, Inf, -Inf and NaN. But “empty” is not a possible value.

    The reason for having NA is to mark that the value isn’t available – seems exactly what you want! Using a negative number is just a more awkward way of doing the same thing – you’d have to remove all negative numbers before calculating mean, sum etc… You can do the same thing with NA – and that functionality is typically built into the functions: by specifying na.rm=TRUE.

    df1 <- data.frame(col_a=c("male","female","male"),col_b=seq(1,30),col_c=seq(11,40))
    df1$col_b[df1$col_b<5|df1$col_b>20] <- NA
    sum(df1$col_b, na.rm=TRUE)    # 200
    median(df1$col_b, na.rm=TRUE) # 12.5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a way to remove lines within multiple csv files, in bash
Looking for an awk (or sed) one-liner to remove lines from the output if
I'm looking to remove the Facebook API from my iPhone project for 2 reasons:
I was looking at this question: How to remove duplicate elements from an xml
I'm looking for a simple Java snippet to remove empty tags from a (any)
I'm looking for a small function that allows me to remove the extension from
How to remove duplicates from a StringCollection in c#? I was looking for a
I am getting multiple similar JSON object from a remote site and looking to
I'm looking for a simplest way to remove duplication in my WPF code. Code
I am looking for the fastest way to remove duplicate values in a string

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.