【问题标题】:Select Items from a List while changing their Col Name in R从列表中选择项目,同时在 R 中更改它们的列名
【发布时间】:2019-03-21 15:19:28
【问题描述】:

所以我使用此代码从列表中选择项目:

itemSelect<- list.select(List,sha,commit$author$date,commit$author$name,
commit$author$email,
commit$message,committer$type)

然后我转换成数据表:

df<-list.rbind(itemSelect)
dt<-as.data.table(df)

但是当我看到我的数据表时,我选择的项目的列名发生了变化,除了 sha。

我认为这是因为“sha”是列表中的第一个。但其他变量的变量带有“$”。并且 col 名称变为:

 sha        V2           V3        V4        V5         V6
d34sx   20-10-2015   23-10-2015    Nic    Comments     user
dftwr   21-11-2015   03-09-2015    Pic    Comments2    user

所以我想问一下是否有办法从列表中选择项目同时更改列名?还是我应该在将其转换为数据表后找到一种方法来批量更改列名?

谢谢!

【问题讨论】:

  • 你能做一个可重现的例子吗?我们没有您的 commit 对象或函数 list.selectlist.rbind
  • 一个可重现的例子会有所帮助....

标签: r list select data.table


【解决方案1】:

您可以使用以下方式发送姓名:

names(dt) <- c("sha","author_date","author_name","author_email","message","type")

【讨论】:

  • 工作得很好!
猜你喜欢
  • 2020-11-27
  • 2014-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多