How to create an empty R vector to add new items

前端 未结 7 848
再見小時候
再見小時候 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:19

    To create an empty vector use:

    vec <- c();
    

    Please note, I am not making any assumptions about the type of vector you require, e.g. numeric.

    Once the vector has been created you can add elements to it as follows:

    For example, to add the numeric value 1:

    vec <- c(vec, 1);
    

    or, to add a string value "a"

    vec <- c(vec, "a");
    

提交回复
热议问题