【发布时间】:2020-01-06 22:59:41
【问题描述】:
我创建了一个基本列表,在这个名为 lista 的列表中(我知道这不是什么大幻想),有 10 个小数据框。 每个数据帧都称为 "numberone","numbertwo",...,"numberten"。
当我加入这个名单时,我看不到他们的名字。 但是我可以在工作区(Rstudio)中看到的输出是这样的
以下是代码和我的尝试:
#creating multiple dataframes and a list and then give a title to this dataframes inside the list.
lista = list()
names = c("numberone","numbertwo","numberthree","numberfour","numberfive","numbersix","numberseven","numbereight","numbernine","numberten")
for (i in 1:10) {
x = rnorm(10)
df = data.frame(x)
assign(names[i],df)
lista[[i]] = df
}
#trying to change manually the names of the dataframes inside the "lista" list
names(lista[1]) = "number one"
print(names(lista[1])) #this gives no results
#trying using dput
output = dput(lista[1])
##trying put manually the name in front of the dput output to rename the first dataframe inside lista..
list('numberone'= structure(list(x = c(0.750704535096297, 1.16925878942967,
0.806475114411396, 1.00973486249489, -0.301553383694518, 0.546485320708262,
1.03645444095639, 0.247820396853631, -1.64294545886444, -0.216784798035195
)), class = "data.frame", row.names = c(NA, -10L)))
#this seems to have renamed the first dataframe but, it's not working anyway
lista$numberone
print(names(lista[1])) #still no results
我已经尝试了几乎所有我能做的事情,但是我不能在列表中给这个单一的数据框起名字。
如何命名这些数据框? 谢谢你
【问题讨论】: