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

  • برمجة R

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

الأجوبة

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"
هل كان المحتوى مفيد؟

معلومات ذات صلة

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...