w3resource

R Programming: Find the levels of factor of a given vector

R Programming: Factors Exercise-1 with Solution

Write a R program to find the levels of factor of a given vector.

Sample Solution :

R Programming Code :

v = c(1, 2, 3, 3, 4, NA, 3, 2, 4, 5, NA, 5)
print("Original vector:")
print(v)
print("Levels of factor of the said vector:")
print(levels(factor(v)))

Sample Output:

[1] "Original vector:"
 [1]  1  2  3  3  4 NA  3  2  4  5 NA  5
[1] "Levels of factor of the said vector:"
[1] "1" "2" "3" "4" "5"                         

R Programming Code Editor:



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

Previous: R Programming Exercises Home.
Next: Write a R program to change the first level of a factor with another level of a given factor.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.