Write an R program to check if a given vector contains a specific element.
EasyProblem Statement
Write an R program to check if a given vector contains a specific element.
Sample Input
Vector: c(1, 2, 3, 4, 5) Element: 3
Sample Output
Element 3 is present in the vector
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
# Predefined structure
vector <- c(1, 2, 3, 4, 5)
element <- 3
if (element %in% vector) {
print(paste("Element", element, "is present in the vector"))} else {
print(paste("Element", element, "is not present in the vector"))}
Input
Vector: c(1, 2, 3, 4, 5) Element: 3
Expected Output
Element 3 is present in the vector