How to add header to a dataset in R?

前端 未结 1 654
死守一世寂寞
死守一世寂寞 2021-02-12 05:54

I need to read the \'\'wdbc.data\' in the following data folder: http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/

Doing this in R is eas

相关标签:
1条回答
  • 2021-02-12 06:04

    You can do the following:

    Load the data:

    test <- read.csv(
              "http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data",
              header=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.

    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")
    
    0 讨论(0)
提交回复
热议问题