R Programming: Find elements which are present in two given data frames
R Programming: Data frame Exercise-20 with Solution
Write a R program to find elements which are present in two given data frames.
Sample Solution:
R Programming Code:
a = c("a", "b", "c", "d", "e")
b = c("d", "e", "f", "g")
print("Original Dataframes")
print(a)
print(b)
print("Elements which are present in both dataframe:")
result = intersect(a, b)
print(result)
Sample Output:
[1] "Original Dataframes" [1] "a" "b" "c" "d" "e" [1] "d" "e" "f" "g" [1] "Elements which are present in both dataframe:" [1] "d" "e"
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to compare two data frames to find the elements in first data frame that are not present in second data frame.
Next: Write a R program to find elements come only once that are common to both given data frames.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook