Here we are explaining how to write an R program to append values to a given empty vector. Using for loop each of the given values are appended to the vector. The assigning of values can be done as like vector[i] <- values[i].
Below are the steps used in the R program to append values to a given empty vector. In this R program, we directly give the values to the vector without using the append() function. Here we are using for loop for the value assigning. The iteration starts from 1 to the length of given vector values. And the value are assigned like V[i] <- Val[i]. Here we are using V as empty vector and variable Val as vector values.
V = c()
Val = c(9,8,7,6,5,4,3,2,1,0)
for (i in 1:length(Val)) {
V[i] <- Val[i]
}
print(V)
## [1] 9 8 7 6 5 4 3 2 1 0
V = c()
Val = c(19, 18, 17, 16, 15, 14, 13, 12, 11, 10)
for (i in 1:length(Val)) {
V[i] <- Val[i]
}
print(V)
## [1] 19 18 17 16 15 14 13 12 11 10