本文翻译自:How to rename a single column in a data.frame?
I know if I have a data frame with more than 1 column, I can use 我知道如果我有一个多于一列的数据框,我可以使用
colnames(x) <- c("col1","col2")
to rename the columns. 重命名列。 How do I do this if it's just one column? 如果只有一栏,该怎么办? Meaning a vector or data frame with only one column in it. 表示其中仅包含一列的向量或数据帧。
Example: 例:
trSamp <- data.frame(sample(trainer$index, 10000))
head(trSamp )
# sample.trainer.index..10000.
# 1 5907862
# 2 2181266
# 3 7368504
# 4 1949790
# 5 3475174
# 6 6062879
ncol(trSamp)
# [1] 1
class(trSamp)
# [1] "dat