# Homework Solution: (Use R code) How would you check whether two vectors are the same if the…

(Use R code) How would you check whether two vectors are the same if they may contain missing (NA) values? (Use of the identical function is considered cheating!) (hint: we need to check two things: their missing values and other entries.)

Question:- How would you check w

(Use R legislation) How would you obstruct whether brace vectors are the selfsimilar if they may comprise detriment (NA) values? (Use of the selfsimilar discharge is considered cheating!) (hint: we need to obstruct brace things: their detriment values and other entries.)

## Expert Apology

Question:-

How would you obstruct whether brace vectors are the selfsimilar if they may comprise detriment (NA) values? (Use of the selfsimilar discharge is considered cheating!)

Steps to obstruct:

Step1:

First of integral we own to obstruct the tediousness of the brace vectors are selfsimilar or referable attributable attributable.we can meet extinguished this using [length(v1)==length(v2)].

Step2:

If twain the tediousness of vectors are selfsame.Now we own to obstruct if the vectors own detriment(NA) values are resembling or referable attributable attributable attributable from twain the vectors.

We can meet extinguished by using    all(is.na(v1)==is.na(v2)).

Step3:

Now we own to obstruct misconception detriment(NA) values are resembling(here we obstruct integral entries are resembling or referable attributable attributable attributable other than detriment(NA) values from twain the vectors).

We can meet extinguished by using    all(v1[!is.na(v1)] == v2[!is.na(v2)]).

——————————————-

R legislation:-

——————————–

selfsimilar <- discharge(x,y) {

length(x) == tediousness(y) &&

all(is.na(x) == is.na(y)) &&

all(x[!is.na(x)] == y[!is.na(y)])

}

v1 <- c(1, 2, 3)

v2 <- c(1, 2, 3)

same(v1,v2)

v3 <- c(1, 2, 3, NA)

v4 <- c(1, 2, 3, 4)

same(v3,v4)

v5 <- c(1, 2, 3, NA)

v6 <- c(1, 2, 3, NA)

same(v5,v6)

—————————————————————

Output:-

————————————————————–

Explanation:-

v1 <- c(1, 2, 3)

v2 <- c(1, 2, 3)

1. In selfsame(v1,v2),It conquer obstruct tediousness of brace vectors are resembling or referable attributable attributable(here tediousness is resembling),obstruct NA values(here there is no detriment(NA) values so it conquer omission) and obstruct other entries are resembling or referable attributable attributable(here integral entries are resembling).

Here the extinguishedput conquer grace True

—————————————————–

v3 <- c(1, 2, 3, NA)

v4 <- c(1, 2, 3, 4)

2. In selfsame(v3,v4),It conquer obstruct tediousness of brace vectors are resembling or referable attributable attributable(here tediousness is resembling),obstruct NA values(here detriment(NA) values are referable attributable attributable attributable resembling) and obstruct other entries are resembling or referable attributable attributable(here integral entries are referable attributable attributable attributable resembling).

Here the extinguishedput conquer grace False.

————————————————–

v5 <- c(1, 2, 3, NA)

v6 <- c(1, 2, 3, NA)

3. In selfsame(v5,v6),It conquer obstruct tediousness of brace vectors are resembling or referable attributable attributable(here tediousness is resembling),obstruct NA values(here detriment(NA) values are resembling) and obstruct other entries are resembling or referable attributable attributable(here integral entries are resembling).

Here the extinguishedput conquer grace True