Activity 02 (Vu22csci0100119)
Activity 02 (Vu22csci0100119)
VU22CSCI0100119
P.SUMANTH
VECTORS
AIM: - write an R program to create a vector which contains 10
elements check whether an element exists in a vector or not and
display the position or index of the element.
PROGRAM:-
# Define initial variables
Registration_no <- "VU22CSCI0100119"
Name <- "P.SUMANTH"
# Check if the value is in the vector and print the index or a message
if (is.element(value, v)) {
cat("Index:", which(v == value), "\n")
} else {
print("Element not found")
}
OUTPUT:-
OUTPUT:-
AIM: - write a R program to display the elements in columns in a 2-D
mateix elements in columns in a 2-D matrix using vectors.
PROGRAM:-
# Define initial variables
Registration_no <- "VU22CSCI0100119"
Name <- "P.SUMANTH"
# Initialize a vector
v <- c(2, 4, 6, 8, 10, 12)
# Initialize vectors
x <- c(218, 217, 213, 214, 215)
cat("Length of x:", length(x), "\n")
y <- c("sowmya", "kala", "prasanna", "mani")
cat("Length of y:", length(y), "\n")
# Initialize vector X
X <- c(8, 2, 7, 1, 11, 2)
# Initialize vector v1
v1 <- c(4, 5, 6, 7)
cat("Type of v1:", typeof(v1), "\n")
# Initialize vector v2
v2 <- c('geeks', '2', 'hello')
cat("Type of v2:", typeof(v2), "\n")
# Initialize vector v3
v3 <- c(TRUE, FALSE, TRUE, NA)
cat("Type of v3:", typeof(v3), "\n")
OUTPUT:-