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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:10:53+00:00 2026-06-09T13:10:53+00:00

I am removing values from a vector by using – (minus sign) in front

  • 0

I am removing values from a vector by using – (minus sign) in front of the index vector. Like this:

scores <- scores[-indexes.to.delete]

Sometimes indexes.to.delete vector is empty, that is N/A. So the scores vector should then remain unchanged. However, I am getting empty scores vector when indexes.to.delete is empty.

Example:

x <- c(1, 2, 3);
y <- c(4, 5, 6);
indexes.to.delete <- which(y < x); # will return empty vector
y <- y[-indexes.to.delete]; # returns empty y vector, but I want y stay untouched

I could code an if statement checking whether indexes.to.delete is empty, but I am wondering if there is a simpler way?

  • 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-09T13:10:55+00:00Added an answer on June 9, 2026 at 1:10 pm

    Maybe use;

    x <- c(1, 2, 3)
    y <- c(4, 5, 6)
    y[!y<x]
    > y[!y<x]
    [1] 4 5 6
    
    x <- c(1, 2, 3)
    y <- c(4, 1, 6)
    > y[!y<x]
    [1] 4 6
    >
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems removing index.php from codeigniter-2. I remember using the same code
Possible Duplicate: R script - removing NA values from a vector I could I
I'm having problems removing a vector from a multidimensional vector I would like to
I was looking around for some elegant solution to removing null values from a
I am removing all non-numeric and non-decimal values using: Regex.Replace(A1B2C3.D4E5F6.G7H8I9, @[^-?\d+\.], ); Output: 123.456.789
After removing hash from URL using window.location.hash='' page getting reloaded in firefox. EDIT Example:
I'm having some trouble removing null values from a 2D array. I'm still a
I'm using the jackson library for serializing/deserializing to/from JSON. I need that this JSON
I have a web method with a signature like this: public string[] ToUpper(string[] values)
I would like to know a method for flagging values in an array, removing

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.