我在使用聚合后制作了一个 data.frame,然后我尝试更改某些列的列名。data.frame (df) 为:
DistanceFromBase Layer Nitrogen x.mean x.sd
1 5 1-2 HN 50.884615 10.841870
2 10 1-2 HN 64.846154 8.008457
3 15 1-2 HN 65.538462 7.500564
4 20 1-2 HN 65.461538 8.448577
5 25 1-2 HN 65.000000 9.055385
6 30 1-2 HN 65.565217 9.806427
我用了
colnames(df)
和 colnames 为:
[1] "DistanceFromBase" "Layer" "Nitrogen" "x"
我想将列名“x.mean”和“x.sd”分别更改为“mean”和“sd”。
colnames(df)[4] <- "mean"
只能将“x”改为“mean”,如:
DistanceFromBase Layer Nitrogen mean.mean mean.sd
1 5 1-2 HN 50.884615 10.841870
2 10 1-2 HN 64.846154 8.008457
3 15 1-2 HN 65.538462 7.500564
4 20 1-2 HN 65.461538 8.448577
5 25 1-2 HN 65.000000 9.055385
6 30 1-2 HN 65.565217 9.806427
如何将列名“x.mean”和“x.sd”更改为“mean”和“sd”。