【发布时间】:2018-01-24 06:35:55
【问题描述】:
我正在尝试重命名 R 中的一列。我有一个列表并想重命名该列表中数据框的一列。
这是我的控制台的摘录。
> colnames(Prem[["TasNSW"]])
[1] "Master Client Number" "Master Client Name" "Policy Number" "State"
[5] "Policy Name" "Year" "Effective Date" "Expiry Date"
[9] "Estimate/Actual" "Total Wages" "Master Client Name "
> colnames(Prem[["TasNSW"]][10]) <- "Remuneration"
> colnames(Prem[["TasNSW"]])
[1] "Master Client Number" "Master Client Name" "Policy Number" "State"
[5] "Policy Name" "Year" "Effective Date" "Expiry Date"
[9] "Estimate/Actual" "Total Wages" "Master Client Name "
我希望看到的是
> colnames(Prem[["NSW"]])
[1] "Master Client Number" "Master Client Name" "Policy Number" "State"
[5] "Policy Name" "Year" "Effective Date" "Expiry Date"
[9] "Estimate/Actual" "Total Wages" "Master Client Name "
> colnames(Prem[["NSW"]][10]) <- "Remuneration"
> colnames(Prem[["NSW"]])
[1] "Master Client Number" "Master Client Name" "Policy Number" "State"
[5] "Policy Name" "Year" "Effective Date" "Expiry Date"
[9] "Estimate/Actual" "Remuneration" "Master Client Name "
我已经多次使用该代码,所以我认为问题是基于它在列表中的存在。我错过了什么?
【问题讨论】:
-
你需要移动
)-colnames(Prem[["TasNSW"]])[10] <- "Remuneration"