R Programming: Test whether a given vector contains a specified element
R Programming: Vector Exercise-10 with Solution
Write a R program to test whether a given vector contains a specified element.
Sample Solution :
R Programming Code :
x = c(10, 20, 30, 25, 9, 26)
print("Original Vectors:")
print(x)
print("Test whether above vector contains 25:")
print(is.element(25, x))
print("Test whether above vector contains 56:")
print(is.element(56, x))
Sample Output:
[1] "Original Vectors:" [1] 10 20 30 25 9 26 [1] "Test whether above vector contains 25:" [1] TRUE [1] "Test whether above vector contains 56:" [1] FALSE
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to sort a Vector in ascending and descending order.
Next: Write a R program to count the specific value in a given vector.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics