1. Introduction
This R program demonstrates the process of appending a value to an initially empty vector. The program creates an empty vector and then adds a new element to it.
2. Program Steps
1. Initialize an empty vector.
2. Define the value to be appended to the vector.
3. Append the value to the empty vector.
4. Display the updated vector.
3. Code Program
# Step 1: Create an empty vector
empty_vector <- c()
# Step 2: Define the value to append
value_to_append <- 10
# Step 3: Append the value to the vector
empty_vector <- c(empty_vector, value_to_append)
# Step 4: Display the updated vector
print("Updated vector:")
print(empty_vector)
Output:
Updated vector: [1] 10
Explanation:
1. empty_vector <- c(): Initializes an empty vector.
2. value_to_append <- 10: Specifies the value 10 to be appended.
3. empty_vector <- c(empty_vector, value_to_append): Appends the value 10 to the empty vector.
4. print("Updated vector:"): Prints a message indicating the updated vector.
5. print(empty_vector): Displays the updated vector, now containing the value 10.
Comments
Post a Comment