Write a R program to append value to a given empty vector

1. Introduction

This R program demonstrates how to append a value to an initially empty vector. The program begins with creating an empty vector and then adds a specified value to it.

2. Program Steps

1. Initialize an empty vector.

2. Define a value to append 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 be appended
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, showing the appended value 10.


Comments