+5 votes
in Programming Languages by (71.8k points)
I want to create a list of vectors. Is there any R function that I should use for it?

1 Answer

+2 votes
by (349k points)
selected by
 
Best answer

The list() function of R can be used to create a list of elements. You can use a vector as an element of the list.

Here is an example:

> a <- c(1,2,3)
> b <- c(11,12,13)
> aa <- list(a,b)
> aa
[[1]]
[1] 1 2 3

[[2]]
[1] 11 12 13

If you want to add a new element to an existing list, you can use [[indx]] where "indx" is the position of the new element.

E.g.

> c <- c(21,22,23)
> aa[[3]] <-c
> aa
[[1]]
[1] 1 2 3

[[2]]
[1] 11 12 13

[[3]]
[1] 21 22 23

Related questions

+4 votes
1 answer
+5 votes
1 answer
+2 votes
1 answer

...