vector of Vectors

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

vector of Vectors

sclarke3
I just learned that vectors can't contain vectors, which frankly simply confuses me (can you imagine arrays or lists in any other language not being able to contain arrays or lists?). At any rate, I need to create a data structure (size to be determined at runtime) which I will instantiate and then fill with vectors using a for loop. Clearly I'm new to the R game. Data Frame doesnt seem to be the right tool clearly.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: vector of Vectors

Schalk Heunis
You want to use list:
a = list()
a[[1]] = c(1,2,3)
a[[2]] = c(1,2,3)

Note the [[..]] operator - check the "An Introduction to R" manual for
more details

Schalk Heunis



On Wed, Sep 9, 2009 at 6:00 AM, <[hidden email]> wrote:
> I just learned that vectors can't contain vectors, which frankly simply confuses me (can you imagine arrays or lists in any other language not being able to contain arrays or lists?). At any rate, I need to create a data structure (size to be determined at runtime) which I will instantiate and then fill with vectors using a for loop. Clearly I'm new to the R game. Data Frame doesnt seem to be the right tool clearly.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: vector of Vectors

Giovanni Petris
In reply to this post by sclarke3

The code below seems to contradict your claim that vectors cannot
contain vectors.

> zz <- vector(mode = "list", length = 3)
> zz
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL

Best,
Giovanni

> Date: Tue, 08 Sep 2009 23:00:54 -0500 (CDT)
> From: [hidden email]
> Sender: [hidden email]
> Precedence: list
>
> I just learned that vectors can't contain vectors, which frankly simply confuses me (can you imagine arrays or lists in any other language not being able to contain arrays or lists?). At any rate, I need to create a data structure (size to be determined at runtime) which I will instantiate and then fill with vectors using a for loop. Clearly I'm new to the R game. Data Frame doesnt seem to be the right tool clearly.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

--

Giovanni Petris  <[hidden email]>
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.