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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:21:46+00:00 2026-06-08T18:21:46+00:00

I am working in R and have found a strange behavior. I can work

  • 0

I am working in R and have found a strange behavior. I can work around it, but it just seems odd, so I was wondering if someone could explain why I get the following output:

> xlabs <- 1:367
> i <- c(2:5)
> Date[xlabs == i]
character(0)
Warning message:
In xlabs == i :
  longer object length is not a multiple of shorter object length
> Date[xlabs = i]
[1] "2011-07-19" "2011-07-20" "2011-07-21" "2011-07-22"

I don’t understand why the logical equals does not apply in this instance, but the simple equals does. I am writing a quick manual for how to do a certain analysis process in R, and I don’t want to have to use a “just because” explanation for my readers’ sake.

  • 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-08T18:21:47+00:00Added an answer on June 8, 2026 at 6:21 pm

    The operator you want is %in%:

    Date[xlabs %in% i]
    

    The = isn’t doing what you think it is. Look at xlabs after the last line of your example; you are setting xlabs to be i as if you did xlabs <- i as = is almost a replacement for <-.

    The == doesn’t work because of the way it is doing comparisons. Consider:

    > 1:10 == 5:7
     [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
    Warning message:
    In 1:10 == 5:7 :
      longer object length is not a multiple of shorter object length
    

    That is doing:

    > 1 == 5
    [1] FALSE
    > 2 == 6
    [1] FALSE
    > 3 == 7
    [1] FALSE
    > 4 == 5
    [1] FALSE
    > 5 == 6
    [1] FALSE
    > 6 == 7
    [1] FALSE
    > 7 == 5
    [1] FALSE
    > 8 == 6
    [1] FALSE
    > 9 == 7
    [1] FALSE
    > 10 == 5
    [1] FALSE
    

    R recycles the shorter vector by repeating it to match the length of the longer. As length(xlabs) is not an exact multiple of length(i) you get the warning, but it is the comparisons themselves that are not selecting anything

    > 1[FALSE]
    numeric(0)
    

    hence the empty vector (in your case an empty character vector).

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

Sidebar

Related Questions

I have createn an app, this app can be found here Everything is working
I found out really strange behavior on relatively simple use case, probably I can't
I have found an strange behavior when use the open file dialog in c#.
I have found a strange behavior in Vim when I attempt to use autocompletion
I'm working on a problem that uses pointer arithmetic and I have found this
I am working on a query, and have found minimal documentation from Microsoft on
I'am currently working on GWTs Activity-Place implementation. Now I have found problem with the
I have a very strange error happening in an App that has been working
I'm working with ASP.Net Membership with FormsAuth and have run into a strange problem.
I have a strange redirects. Desired behavior is: when I type URL http://xyz.localhost there

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.