所以我将数据集作为我在循环中创建的23行乘6列的列表。给定列表称为List.X
,但给定循环中该列表名称的变量为curr.list
,这只是all.possible.Lists[i]
。
对于长度感到抱歉,我还不擅长创建示例数据,因此将使用我的原始数据。此代码生成我的一个数据列表。循环的每次迭代都会带来一个新的迭代。
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")))
一旦我填充了我的列表,我想将其转换为23行乘6列的矩阵,我正在使用cbind。如果我使用它,
List.X <- do.call("cbind",List.X)
它产生所需的输出。但是,考虑到curr.list = "List.X"
,我需要尝试填充名为curr.list的变量,所以我试试这个
assign(curr.list,cbind(get(curr.list)))
但是,这会导致输出与所需的输出不同(上图)。
我是R的新手并且在这个上有点迷失并且会感激任何提示。