0

So I have data sets as lists that are 23 rows by 6 columns that I create in a loop. A given list is called List.X, though the variable for that list name in a given loop is curr.list, which is simply all.possible.Lists[i].

Sorry about the length, I'm not good at creating example data yet, so will use my original data. This code generates one of my data lists. Each iteration of the loop brings in a new one of these.

curr.list <- "List.X" #for this example, this happens as part of a loop, taking the name from another list of names.    
List.X <- list(structure(c(3.08, 2.88, 3.05, 3.02, 3.01, 3.08, 3.03, 2.98, 2.81, 
    2.51, 2.740, 2.80, 2.46, 2.67, 2.75, 2.7, 3, 2.75, 2.96, 3.225, 2.93, 
    2.71, 2.79), .Names = c("FBMB1", "FBMB2", 
    "FBMB3", "FBMB4", "FBMB5", "FBMB6", "FBMB7", "FBMB8", "FBMB9", 
    "FBMB10", "FBMB11", "FBMB12", "FBMB13", "FBMB14", "FBMB15", "FBMB16", 
    "FBMB17", "FBMB18", "FBMB19", "FBMB20", "FBMA.RelComp", "FBMB.BusComp", 
    "FBMA.Visit")), structure(c(2.80, 2.87, 
    2.83, 2.80, 2.83, 2.96, 2.80, 2.93, 2.67, 2.25, 
    2.677, 2.48, 2.32, 2.64, 2.54, 2.51, 3.06, 2.77, 
    3, 3.12, 2.84, 2.56, 2.79
    ), .Names = c("FBMB1", "FBMB2", "FBMB3", "FBMB4", "FBMB5", "FBMB6", 
    "FBMB7", "FBMB8", "FBMB9", "FBMB10", "FBMB11", "FBMB12", "FBMB13", 
    "FBMB14", "FBMB15", "FBMB16", "FBMB17", "FBMB18", "FBMB19", "FBMB20", 
    "FBMA.RelComp", "FBMB.BusComp", "FBMA.Visit")), structure(c(3.57, 
    2.85, 3, 3.14, 3.28, 3.28, 3.42, 3.28, 3.28, 2.42, 2.71, 3.14, 2.28, 2.85, 
    3, 3.14, 3.28, 2.711, 3.14, 3.71, 2.542, 2.90, 2.4375), .Names = c("FBMB1", 
    "FBMB2", "FBMB3", "FBMB4", "FBMB5", "FBMB6", "FBMB7", "FBMB8", 
    "FBMB9", "FBMB10", "FBMB11", "FBMB12", "FBMB13", "FBMB14", "FBMB15", 
    "FBMB16", "FBMB17", "FBMB18", "FBMB19", "FBMB20", "FBMA.RelComp", 
    "FBMB.BusComp", "FBMA.Visit")), structure(c(3.16, 2.75, 3.08, 3.25, 3, 3.18, 3, 2.83, 2.75, 2.63, 3, 3, 2.66, 2.58, 3.16, 2.75, 2.91, 2.75, 2.83, 
    3.16, 2.84, 2.82, 2.54), .Names = c("FBMB1", "FBMB2", "FBMB3", "FBMB4", "FBMB5", "FBMB6", 
    "FBMB7", "FBMB8", "FBMB9", "FBMB10", "FBMB11", "FBMB12", "FBMB13", 
    "FBMB14", "FBMB15", "FBMB16", "FBMB17", "FBMB18", "FBMB19", "FBMB20", 
    "FBMA.RelComp", "FBMB.BusComp", "FBMA.Visit")), structure(c(3.23, 
    3.15, 3.23, 3.23, 3.153, 3.15, 3.31, 3.071, 2.78, 
    2.71, 2.71, 3, 2.78, 2.71, 2.85, 2.64, 2.85, 2.71, 
    3, 3.42, 3.42, 2.80, 3.17), .Names = c("FBMB1", "FBMB2", "FBMB3", "FBMB4", "FBMB5", "FBMB6", 
    "FBMB7", "FBMB8", "FBMB9", "FBMB10", "FBMB11", "FBMB12", "FBMB13", 
    "FBMB14", "FBMB15", "FBMB16", "FBMB17", "FBMB18", "FBMB19", "FBMB20", 
    "FBMA.RelComp", "FBMB.BusComp", "FBMA.Visit")), structure(c(3.22, 
    2.83, 3.29, 3.05, 3.11, 3.11, 3.11, 3, 2.93, 2.76, 2.70, 2.94, 2.41, 2.70, 
    2.625, 2.875, 2.9375, 2.75, 2.875, 3.0625, 2.88, 
    2.78, 2.71), .Names = c("FBMB1", "FBMB2", 
    "FBMB3", "FBMB4", "FBMB5", "FBMB6", "FBMB7", "FBMB8", "FBMB9", 
    "FBMB10", "FBMB11", "FBMB12", "FBMB13", "FBMB14", "FBMB15", "FBMB16", 
    "FBMB17", "FBMB18", "FBMB19", "FBMB20", "FBMA.RelComp", "FBMB.BusComp", 
    "FBMA.Visit")))

Once I've populated my list, I want to convert it to a matrix of 23 rows by 6 columns, I am using cbind. If I use this,

List.X <- do.call("cbind",List.X)

It produces the desired output. However, given that curr.list = "List.X", I need to try to populate a variable named curr.list, so I try this

assign(curr.list,cbind(get(curr.list)))

This, however, results in different output to the desired (above).

I'm new to R and am a bit lost on this one and would appreciate any hints.

Alex
  • 971
  • 4
  • 15
  • 28
  • 1
    If you are new to R you should never need to use the `assign()` function, there are almost always better ways. Unfortunately your description of the problem is hard to understand because the description of the objects involved and results desired isn't very precise. You should edit your question to include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output. – MrFlick Mar 02 '15 at 02:07
  • @MrFlick thanks for the link. I've put some more detail in, along with a reproducible example. Please excuse the long data set; not great at creating random data sets in the shape i want yet (e.g. rand(23,6) in MATLAB). – Alex Mar 02 '15 at 03:04

0 Answers0