如何在R中的数据集中添加标题?

编程入门 行业动态 更新时间:2024-10-10 02:22:42
本文介绍了如何在R中的数据集中添加标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要阅读以下数据文件夹中的wdbc.data: archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/

I need to read the ''wdbc.data' in the following data folder: 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( "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中的数据集中添加标题?

本文发布于:2023-11-28 19:03:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标题   数据   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!