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?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework