如何在R中的数据集中添加标题? [英] How to add header to a dataset in R?
问题描述
我需要阅读以下数据文件夹中的wdbc.data:
http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/
I need to read the ''wdbc.data' in the following data folder: http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/
在R中执行此操作很容易使用命令read.csv,但由于标题缺少如何添加它?我有信息但不知道如何做到这一点,我宁愿不编辑数据文件。
Doing this in R is easy using command read.csv but as the header is missing how can I add it? I have the information but don't know how to do this and I'd prefer do not edit the data file.
推荐答案
您可以执行以下操作:
加载数据:
test <- read.csv(
"http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data",
header=FALSE)
请注意,头的默认值
参数
read.csv
是 TRUE
所以为了获得你需要设置的所有行到 FALSE
。
Note that the default value of the header
argument for read.csv
is TRUE
so in order to get all lines you need to set it to FALSE
.
将数据添加到data.frame中的不同列中
Add names to the different columns in the data.frame
names(test) <- c("A","B","C","D","E","F","G","H","I","J","K")
并且我知道的更快(不是重新加载整个数据集):
or alternative and faster as I understand (not reloading the entire dataset):
colnames(test) <- c("A","B","C","D","E","F","G","H","I","J","K")
这篇关于如何在R中的数据集中添加标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!