Q:

Write a R program to find all elements of a given list that are not in another given list

0

Write a R program to find all elements of a given list that are not in another given list.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

l1 = list("x", "y", "z")
l2 = list("X", "Y", "Z", "x", "y", "z")
print("Original lists:")
print(l1)
print(l2)
print("All elements of l2 that are not in l1:")
setdiff(l2, l1)

Sample Output:

[1] "Original lists:"
[[1]]
[1] "x"

[[2]]
[1] "y"

[[3]]
[1] "z"

[[1]]
[1] "X"

[[2]]
[1] "Y"

[[3]]
[1] "Z"

[[4]]
[1] "x"

[[5]]
[1] "y"

[[6]]
[1] "z"

[1] "All elements of l2 that are not in l1:"
[[1]]
[1] "X"

[[2]]
[1] "Y"

[[3]]
[1] "Z"

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now