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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:05:15+00:00 2026-05-23T12:05:15+00:00

According to the R language definition , the difference between & and && (correspondingly

  • 0

According to the R language definition, the difference between & and && (correspondingly | and ||) is that the former is vectorized while the latter is not.

According to the help text, I read the difference akin to the difference between an “And” and “AndAlso” (correspondingly “Or” and “OrElse”)…
Meaning:
That not all evaluations if they don’t have to be (i.e. A or B or C is always true if A is true, so stop evaluating if A is true)

Could someone shed light here?
Also, is there an AndAlso and OrElse in R?

  • 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-23T12:05:15+00:00Added an answer on May 23, 2026 at 12:05 pm

    The shorter ones are vectorized, meaning they can return a vector, like this:

    ((-2:2) >= 0) & ((-2:2) <= 0)
    # [1] FALSE FALSE  TRUE FALSE FALSE
    

    The longer form is not, and so (as of 4.3.0) must be given inputs of length 1. (Hooray! Less checking necessary, see below.)

    Until R 4.3.0, giving && inputs of length > 1 did not throw an error, but instead evaluated left to right examining only the first element of each vector, so the above gave:

    ((-2:2) >= 0) && ((-2:2) <= 0)
    # [1] FALSE
    

    As the help page says, this makes the longer form "appropriate for programming control-flow and [is] typically preferred in if clauses."

    So you want to use the long forms only when you are certain the vectors are length one, and as of 4.3.0, R enforces this.

    If you’re using a previous version, you should be absolutely certain your vectors are only length 1, such as in cases where they are functions that return only length 1 booleans. You want to use the short forms if the vectors are length possibly >1. So if you’re not absolutely sure, you should either check first, or use the short form and then use all and any to reduce it to length one for use in control flow statements, like if.

    The functions all and any are often used on the result of a vectorized comparison to see if all or any of the comparisons are true, respectively. The results from these functions are sure to be length 1 so they are appropriate for use in if clauses, while the results from the vectorized comparison are not. (Though those results would be appropriate for use in ifelse.)

    One final difference: the && and || only evaluate as many terms as they need to (which is often called short-circuiting). For example, here’s a comparison using an undefined value a; if it didn’t short-circuit, as & and | don’t, it would give an error.

    a
    # Error: object 'a' not found
    TRUE || a
    # [1] TRUE
    FALSE && a
    # [1] FALSE
    TRUE | a
    # Error: object 'a' not found
    FALSE & a
    # Error: object 'a' not found
    

    Finally, see section 8.2.17 in The R Inferno, titled "and and andand".

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

Sidebar

Related Questions

I'm repeatedly getting confused between Language & Culture in Symfony. - I'm setting culture
According to CSharp Language Specification. An interface defines a contract that can be implemented
What exactly the difference between interpreted and compiled language.For example I want print the
According to the Java Language Specification : If there are any enclosing try statements
According to the Java Language Sepecification , 3rd edition: It is a compile-time error
According to the computer language benchmark game, the LuaJIT implementation seems to beat every
According to Jython's documentation : Jython is an implementation of the Python language for
You guys know in Pastebin how according to the selected language, the code is
I start to learn class in PHP. According to my experience with other language,
According to Wikipedia, on the Comparison of programming languages page, it says that F#

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.