I have list y like below. I want to change the first column name of each data frame (rn) to the name of the data frame (SA, TA). So it will look like y1.
下面列出了y。我想将每个数据帧(rn)的第一列名称更改为数据帧的名称(SA, TA)。它看起来像y。
> y
$SA
rn X1 X2 X3 X4 X5 X6
1: timepoint 0 3.75 4.25 4.5 4.75 5
2: plot 234 304 285 279 256 238
$TA
rn X7 X8 X9 X10 X11 X12
1: timepoint 0 5 4.25 3.75 4.75 4.5
2: plot 208 299 272 261 254 218
> y1
$SA
SA X1 X2 X3 X4 X5 X6
1: timepoint 0 3.75 4.25 4.5 4.75 5
2: plot 234 304 285 279 256 238
$TA
TA X7 X8 X9 X10 X11 X12
1: timepoint 0 5 4.25 3.75 4.75 4.5
2: plot 208 299 272 261 254 218
1 个解决方案
#1
2
Those list elements look like data tables, so it should be as simple as
这些列表元素看起来像数据表,所以应该简单到
y1 <- Map(setnames, y, "rn", names(y))
Replace "rn"
with 1
if you want to index by the first column instead of by the column name "rn".
如果你想索引第一列而不是列名“rn”,就用1替换“rn”。
#1
2
Those list elements look like data tables, so it should be as simple as
这些列表元素看起来像数据表,所以应该简单到
y1 <- Map(setnames, y, "rn", names(y))
Replace "rn"
with 1
if you want to index by the first column instead of by the column name "rn".
如果你想索引第一列而不是列名“rn”,就用1替换“rn”。