简体   繁体   English

如何将列表项转换为另一个列表项的矢量名称

[英]How to convert a list item to a vector name for another list item

So I have this list (I4);所以我有这个列表(I4);

paste(I4)
[1] "d2_cont_v1.xlsx" "d2_cont_v2.xlsx" "d2_cont_v3.xlsx" "d3_cont_v1.xlsx" "d3_cont_v2.xlsx" "d3_cont_v3.xlsx"
 [7] "gfp_v1.xlsx"     "gfp_v2.xlsx"     "gfp_v3.xlsx"     "mu_v1.xlsx"      "mu_v2.xlsx"      "mu_v3.xlsx"     
[13] "wt_v1.xlsx"      "wt_v2.xlsx"      "wt_v3.xlsx"

and another list (Inj4CACNA) which is a list of 15 data frames.另一个列表(Inj4CACNA)是一个包含 15 个数据帧的列表。 I am converting the first item in the 'Inj4CACNA' list to a standalone data frame.我正在将“Inj4CACNA”列表中的第一项转换为独立数据框。 Then, I want to label this first data frame to be a vector that has the same name as the first item in the "I4" list.然后,我希望 label 这个第一个数据框是一个与“I4”列表中的第一项同名的向量。 I cannot for the life of me figure out how to do this.我终生无法弄清楚如何做到这一点。

(The eventual goal is to output csv files of each of these 15 data frames with these names, and.xlsx will be removed too) (最终目标是将这15个数据框的每一个的output csv个文件同名,and.xlsx也将被移除)

Obviously I could just copy and paste this myself but I have lots of files I need to do similar things with so want to do it more efficiently.显然我可以自己复制和粘贴这个,但我有很多文件需要用它来做类似的事情,所以我想更有效地做这件事。

I know that I can make my standalone data frame from Inj4CACNA by doing;我知道我可以通过这样做从 Inj4CACNA 制作我的独立数据框;

as.data.frame(Inj4CACNA[[1]])

but I don't understand how to write a command that would turn a list item into a vector name .但我不明白如何编写将列表项转换为矢量名称的命令。

I know to create a vector from a list item I can use我知道从我可以使用的列表项创建一个向量

vectorname = unlist(I4[1])

or to paste the list item as characters或者将列表项粘贴为字符

paste(I4[1])

But I don't know how to apply it in the way I want.但我不知道如何以我想要的方式应用它。 Help would be much appreciated.帮助将不胜感激。

Nevermind, I figured it out;没关系,我想通了; For anyone curious;对于任何好奇的人;

vector = unlist(I4[1])
x = as.data.frame(Inj4CACNA[1])
assign(vector, x)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM