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 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 large script that has no database connection yet. I need one
I have a script that has a bunch of different parameterized functions. Is it
I have a script that has a few timeouts, draws a menu using Raphael
I have a script that has PHP on it, and a link that goes
I have A Script that has a Select statement to go to multiple sub
I have a bash script that has set -x in it. Is it possible
I have a PHP script that has a runtime of 34 seconds. But it
I have a bash script that has this function in it: function start_vi() {
I have a Bourne Shell script that has several functions in it, and allows
I have a #!/bin/sh script that has the following line: if [ ! -x

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.