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

The Archive Base Latest Questions

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

I have a script that has a bunch of quality control checksums and it

  • 0

I have a script that has a bunch of quality control checksums and it got caught on a dataset that had no need to remove any samples (rows) due to quality control. However, this script gave me an unexpected result of a dataframe with zero rows. With example data, why does this work:

data(iris)
##get rid of those pesky factors
iris$Species <- NULL
med <- which(iris[, 1] < 4.9)
medtemp <- iris[-med, ]
dim(medtemp)
[1] 134   4

but this returns a dataframe of zero rows:

small <- which(iris[, 1] < 4.0)
smalltemp <- iris[-small, ]
dim(smalltemp)
[1] 0 4

As does this:

x <- 0
zerotemp <- iris[-x, ]
dim(zerotemp)
[1] 0 4

It seems that the smalltemp dataframe should be the same size as iris since there are no rows to remove at all. Why is this?

  • 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-22T18:29:00+00:00Added an answer on May 22, 2026 at 6:29 pm

    Copied verbatim from Patrick Burns’s R Inferno p. 41 (I hope this constitutes “fair use” — if someone objects I’ll remove it)

    negative nothing is something

    > x2 <- 1:4
    > x2[-which(x2 == 3)]
    [1] 1 2 4
    

    The command above returns all of the values in x2 not equal to 3.

    > x2[-which(x2 == 5)]
    numeric(0)
    

    The hope is that the above command returns all of x2 since no elements are
    equal to 5. Reality will dash that hope. Instead it returns a vector of length
    zero.
    There is a subtle difference between the two following statements:

    x[]
    x[numeric(0)]
    

    Subtle difference in the input, but no subtlety in the difference in the output.
    There are at least three possible solutions for the original problem.

    out <- which(x2 == 5)
    if(length(out)) x2[-out] else x2
    

    Another solution is to use logical subscripts:

    x2[!(x2 %in% 5)]
    

    Or you can, in a sense, work backwards:

    x2[ setdiff(seq along(x2), which(x2 == 5)) ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python script that has to launch a shell command for every
I have a script that needs to run after tomcat has finished starting up
I have a script that takes a table name and generates a control file
I have a script that successfully encrypts a credit card. I need it to
I've got an IronPython script that executes a bunch of SQL statements against a
I have a long running redgate script that is applying a bunch of schema
I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example),
I have a script that retrieves objects from a remote server through an Ajax
I have a script that checks responses from HTTP servers using the PEAR HTTP
I have a script that renders graphs in gnuplot. The graphs all end up

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.