In R, you can append an item to a vector using the `c()` function.
In this example,
vec
with some initial elements.c()
function to append a new item to the vector.# Create a vector with initial elements
vec <- c(1, 2, 3)
# Append item to the vector using c() function
vec <- c(vec, 4)
# Print the modified vector
print(vec)
[1] 1 2 3 4
In this example,
names
with some initial names.c()
function to append a new name to the vector.# Create a character vector with initial names
names <- c("John", "Alice", "Bob")
# Append a name to the vector using c() function
names <- c(names, "Emma")
# Print the modified vector
print(names)
[1] "John" "Alice" "Bob" "Emma"
In this tutorial, we learned How to Append an Item to a Vector in R language with well detailed examples.