R Programming: Create a data frame using two given vectors and display the duplicated elements and unique rows of the said data frame
R Programming: Data frame Exercise-24 with Solution
Write a R program to create a data frame using two given vectors and display the duplicated elements and unique rows of the said data frame.
Sample Solution :
R Programming Code :
a = c(10,20,10,10,40,50,20,30)
b = c(10,30,10,20,0,50,30,30)
print("Original data frame:")
ab = data.frame(a,b)
print(ab)
print("Duplicate elements of the said data frame:")
print(duplicated(ab))
print("Unique rows of the said data frame:")
print(unique(ab))
Sample Output:
[1] "Original data frame:" a b 1 10 10 2 20 30 3 10 10 4 10 20 5 40 0 6 50 50 7 20 30 8 30 30 [1] "Duplicate elements of the said data frame:" [1] FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE [1] "Unique rows of the said data frame:" a b 1 10 10 2 20 30 4 10 20 5 40 0 6 50 50 8 30 30
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to count the number of NA values in a data frame column.
Next: Write a R program to call the (built-in) dataset airquality. Check whether it is a data.frame or not? Order the entire data frame by the first and second column.
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