How to create an empty R vector to add new items

前端 未结 7 849
再見小時候
再見小時候 2020-12-07 10:42

I want to use R in Python, as provided by the module Rpy2. I notice that R has very convenient [] operations by which you can extract the specific columns or li

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 11:13

    As pointed out by Brani, vector() is a solution, e.g.

    newVector <- vector(mode = "numeric", length = 50)

    will return a vector named "newVector" with 50 "0"'s as initial values. It is also fairly common to just add the new scalar to an existing vector to arrive at an expanded vector, e.g.

    aVector <- c(aVector, newScalar)

提交回复
热议问题