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: List the distinct values in a vector from a given vector

R Programming: Vector Exercise-18 with Solution

Write a R program to list the distinct values in a vector from a given vector.

Sample Solution :

R Programming Code :

v = c(10, 10, 10, 20, 30, 40, 40, 40, 50)
print("Original vector:")
print(v)
print("Distinct values of the said vector:")
print(unique(v))

Sample Output:

[1] "Original vector:"
[1] 10 10 10 20 30 40 40 40 50
[1] "Distinct values of the said vector:"
[1] 10 20 30 40 50                         

R Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a R program to extract every nth element of a given vector.
Next: Write a R program to find the elements of a given vector that are not in another given vector.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?