Here are three ways to append multiple elements to a Vector in R:
- Using c()
- Using append()
- Using <<- operator
Method 1: Using c()
vec <- c(11, 21, 46)
combined_vec <- c(vec, 18, 19, 29)
cat("Appended Vector: ", combined_vec, "\n")
Output
Appended Vector: 11 21 46 18 19 29
Method 2: Using append()
vec1 <- c(11, 21, 46)
vec2 <- c(18, 19, 29)
combined_vec <- append(vec1, vec2)
cat("Appended Vector: ", combined_vec, "\n")
Output
Appended Vector: 11 21 46 18 19 29
Method 3: Using <<- operator
vec1 <- c(11, 21, 46)
vec2 <- c(18, 19, 29)
combined_vec <<- c(vec1, vec2)
cat("Appended Vector: ", combined_vec, "\n")
Output
Appended Vector: 11 21 46 18 19 29
That’s it
Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.