我正在尝试重命名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 "
我已多次使用该代码,所以我认为问题是基于它在列表中的存在。我错过了什么?
答案 0 :(得分:3)
你错了这里的右括号:
df2 <- subset(df1, ID %in% vector)
相反,试试这个:
colnames(Prem[["TasNSW"]][10]) <- "Remuneration"
你会得到预期的结果