Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

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?