method1 = function(n) { vec = NULL # Or vec = c() for (i in seq_len(n)) vec = c(vec, i) vec}Method 2 creates an object of the final length and then changes the values in the object by subscripting:方法 2 创建一个最终长度的对象,然后通过下标更改对象中的值:method2 = function(n) { vec = numeric(n) for (i in seq_len(n)) vec[i] = i vec}Method 3 directly creates the final object:方法三直接创建最终对象:method3 = function(n) seq_len(n)