[R] Storing vectors as vectors in a list without losing each individual vector

Patricia Seo pseo at stanford.edu
Tue Oct 14 01:27:35 CEST 2014


Hi everyone,

My help request is similar to what was asked by Ken Termiso on April 18th, 2005. Link here: https://stat.ethz.ch/pipermail/r-help/2005-April/069729.html

Matt Wiener answered with suggesting a vector list where you hand type each of the vectors. This is not what I want to do. What I want to do is automate the process. So, in other words creating a list through a loop. 

For example:

My data frame is called "df" and I have four variables/vectors that are v7, v8, v9, 10. Each variable/vector is an integer (no character strings). I want to create a list called "Indexes" so that I can use this list for "for-in" loops to SEPARATELY plot each and every variable/vector. 

If I followed Matt Wiener's suggestion, I would input this:


Indexes = list()
Indexes[[1]] = df$v7 
Indexes[[2]] = df$v8
Indexes[[3]] = df$v9
Indexes[[4]] = df$v10

But if I want to include more than four variable/vectors (let's say I want to include 25 of them!), I do not want to have to type all of it. If I do the following command:

Indexes <- c(df$v7, df$v8, df$v9, df$v10)

then I run into the same problem as Ken Termiso with having all the integers in one vector. I need to keep the variables/vectors separate. 

Is this just not possible in R? Any help would be great. Thank you!



More information about the R-help mailing list