The question concerns the practical difference between the == and %in% operators in R.

I have run into an instance at work where filtering with either operator gives different results (e.g. one results on 800 rows, and the other 1200). I have a problem in the past and am able to validate that ensures I get the results I desire. However, I am still stumped regarding how they are different. Jun 1 11 views

## 1 answer to this question.

According to help('percent in percent'), percent in percent is a value matching function that "returns a vector of the places of (first) matches of its first parameter in its second." This implies that you might compare vectors of various lengths to determine whether at least one element in one vector matches an element in another. The output will have a length equal to the vector being compared (the first one).

1:2 in percentage return (1:2,5)
# True, True

Replicate (1:2,5) in percent 1:2 # True, True, True, True, True, True, True

The output is longer in seconds; take note.
If two things are exactly equal, the comparison operator == is used. The elements of the vectors will be compared element-by-element if they are similar in length. Vectors will be recycled if not. The output's length answered Jun 23 by
• 2,960 points

## What's the difference between "*" and "+" in lm() in R?

Lm is a fitting method for linear ...READ MORE

## Why is it not advisable to use attach() in R, and what should I use instead?

There is one more option that applies ...READ MORE

## To speed up the tapply function in R, or another function to convert data frame into a matrix

I must turn a sizable dataset into ...READ MORE

## Standard Deviation in R Seems to be Returning the Wrong Answer - Am I Doing Something Wrong?

An easy illustration of standard deviation calculation: The ...READ MORE

## How to make loop for one-at-a time logistic regression in R?

You're probably looking for something similar to ...READ MORE

## What is the difference between [] and [[]] notations to access the elements of a list or dataframe in R?

R provides 3 basic indexing operators. Refer ...READ MORE

## Understanding the result of modulo operator: %%

Just trying to understand how the %% ...READ MORE

## Use of \$ and %% operators in R

According to help('percent in percent'), percent in ...READ MORE