Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an empty R vector to add new items

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 lines. How could I achieve such a function by Python scripts?

My idea is to create an R vector and add those wanted elements into this vector so that the final vector is the same as that in R. I created a seq(), but it seems that it has an initial digit 1, so the final result would always start with the digit 1, which is not what I want. So, is there a better way to do this?

like image 266
ligwin Avatar asked Aug 05 '10 10:08

ligwin


People also ask

How do I create an empty list and add values in R?

To create an empty list in R, use the vector() function. The vector() function takes two arguments: mode and length. The mode is, in our case, is a list, and length is the number of elements in the list, and the list ends up actually empty, filled with NULL.

How do I add elements to a vector in R?

To append elements to a Vector in R, use the append() method. The append() is a built-in method that adds the various integer values into a Vector in the last position.


1 Answers

vec <- vector() 

See also vector help

?vector 
like image 114
Brani Avatar answered Sep 29 '22 15:09

Brani