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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:15:46+00:00 2026-05-18T03:15:46+00:00

In R, let’s say we have a vector area = c(rep(c(26:30), 5), rep(c(500:504), 5),

  • 0

In R, let’s say we have a vector
area = c(rep(c(26:30), 5), rep(c(500:504), 5), rep(c(550:554), 5), rep(c(76:80), 5)) and another vector yield = c(1:100).
Now, say I want to index like so:

> yield[area==27]
[1]  2  7 12 17 22
> yield[area==501]
[1] 27 32 37 42 47

No problem, right? But weird things start happening when I try to index it by using c(A, B). (and even weirder when I try c(min:max) …)

> yield[area==c(27,501)]
[1]  7 17 32 42

What I’m expecting is of course the instances that are present in both of the other examples, not just some weird combination of them. This works when I can use the pipe OR operator:

> yield[area==27 | area==501]
 [1]  2  7 12 17 22 27 32 37 42 47

But what if I’m working with a range? Say I want index it by the range c(27:503)? In my real example there are a lot more data points and ranges, so it makes more sense, please don’t suggest I do it by hand, which would essentially mean:

yield[area==27 | area==28 | area==29 | ... | area==303 | ... | area==500 | area==501]

There must be a better 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-05-18T03:15:47+00:00Added an answer on May 18, 2026 at 3:15 am

    You want to use %in%. Also notice that c(27:503) and 27:503 yield the same object.

    > yield[area %in% 27:503]
     [1]   2   3   4   5   7   8   9  10  12  13  14  15  17
    [14]  18  19  20  22  23  24  25  26  27  28  29  31  32
    [27]  33  34  36  37  38  39  41  42  43  44  46  47  48
    [40]  49  76  77  78  79  80  81  82  83  84  85  86  87
    [53]  88  89  90  91  92  93  94  95  96  97  98  99 100
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say i have two tables in db: Car and Part. Car owns arbitrialy
Let’s say I have a number like 0x448 . In binary this is 0100
Let's say I have a 12-bit Analog to Digital Converter (4096 bins). And let's
Let's say I have a structure named vertex with a method that adds two
Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have window.open (without name parameter), scattered in my project and I
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have an facebook application running using the JS SDK. First user

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.