Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post How to compare the values of two vectors in R? appeared first on finnstats.

If you are interested to learn more about data science, you can find more articles here finnstats.

How to compare the values of two vectors in R?, Using match() and %in% we can compare vectors

Today, we’ll talk about comparing two R vectors to see what components (values).

Here, we have two choices:

The indexes of common elements are returned by the match () function in R.

1. Indicating if a value from the first vector was present in the second.
2. The percent in percent operation produces a vector of True or False answers.

## Finding Values in Vectors using R Match

Starting with the R match() function, let’s go on.

`Value<-c(15,13,12,14,12,15,30)`

The first position of the matching value is returned by the r match example.

```match(12, Value)
[1] 3```

Example of an r match with multiple values

```match (c(13,12), Value)
[1] 2 3```

The initial position of each of the two values is returned by the R match function when we pass it a vector of multiple values.

## Operator – Boolean Equivalent for percent in percent

Do you only require a True/False response?

Use the percent in percent operator, if possible. Similar operations are carried out, and the result is returned as a Boolean indicator indicating if the value is present.

For an example of the R percent in percent operator

by utilizing the percent in percent operator, check for a single value.

```14 %in% Value
[1] TRUE```

Utilize the percent in percent operator to verify a vector of multiple values.

```c(10, 12) %in% Value
[1] FALSE  TRUE```

what values the percent in percent operator treats when it can’t

```c(10, 12, 14) %in% Value
[1] FALSE  TRUE  TRUE```

## Summary

The percent in percent operator and R Match; We can compare the values of two vectors using these two tools.

If you are interested to learn more about data science, you can find more articles here finnstats.

The post How to compare the values of two vectors in R? appeared first on finnstats.