How to add new elements to an array in the R language?

To add new elements to an array in R language, you can use either the c() function or the append() function. Here are examples of both methods:

Utilize the c() function:

# 创建一个包含元素的数组
arr <- c(1, 2, 3, 4)

# 添加新的元素到数组中
arr <- c(arr, 5)

print(arr)

utilize the append() function:

# 创建一个包含元素的数组
arr <- c(1, 2, 3, 4)

# 添加新的元素到数组中
arr <- append(arr, 5)

print(arr)

Both the c() function and the append() function can be used to add new elements to an array.

bannerAds