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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:07:11+00:00 2026-05-24T10:07:11+00:00

Why doesn’t subset() work with a logical and && operator combining two conditions? >

  • 0

Why doesn’t subset() work with a logical and && operator combining two conditions?

> subset(tt, (customer_id==177 && visit_date=="2010-08-26"))
<0 rows> (or 0-length row.names)

but they each work individually:

> subset(tt, customer_id==177)

> subset(tt, visit_date=="2010-08-26")

(Want to avoid using large temporary variables – my dataset is huge)

  • 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-24T10:07:12+00:00Added an answer on May 24, 2026 at 10:07 am

    From the help page for Logical Operators, accessible by ?"&&":

    & and && indicate logical AND and | and || indicate logical OR. The shorter form performs elementwise comparisons in much the same way as arithmetic operators. The longer form evaluates left to right examining only the first element of each vector. Evaluation proceeds only until the result is determined. The longer form is appropriate for programming control-flow and typically preferred in if clauses.

    (R version 2.13-0)

    In other words, when using subset, use the single &.


    Here is an illustration of the difference:

    c(1,1,0,0) & c(1,0,1,0)
    [1]  TRUE FALSE FALSE FALSE
    
    c(1,1,0,0) && c(1,0,1,0)
    [1] TRUE
    

    If this looks quirky compared to other programming paradigms, remember that R needs to provide a vectorised form of the operator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Doesn't seem to work for me, maybe I just doing it wrong
Why doesn't this work (when parameter is set to 1) : SELECT * FROM
doesn't work.. can't find any solution to prevent submit page reload only if ajax
Why doesn't this work? - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { if (TRACE_LOG) NSLog(@%s, __FUNCTION__);
This doesn't work panel1.layout: layout [ offset: 0x0 yuml-image: image img ] panel2.layout: layout
autowrite doesn't seem to work when switching tab in vim. Is there a way
This doesn't work. I've got an exception from SQL databse that column does not
Why doesn't my MySQL query work? Query: DELETE FROM jos_community_awards a LEFT JOIN jos_community_users
Why doesn't the following work in Python? def make_class(a): class A(object): a=a return A
Doesn't work with other modules, but to give an example. I installed Text::CSV_XS with

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.