R import .data文件扩展

时间:2016-08-02 00:09:57

标签: r data-import

您好我正在尝试从网址导入数据:https://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data但它始终将其作为单行导入。我将数据拆分为“\ t”,但它仍无法正常工作。我的R代码;

    bostonHousing <- read.table("https://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data",
 col.names= c("CRIM","ZN","INDUS","CHAS","NOX","RM","AGE","DIS","RAD","TAX","PTRATIO","B","LSTAT","MEDV"),
                                  dec=",",sep = "\t")

1 个答案:

答案 0 :(得分:2)

文件没有标签分隔,它是以空格分隔的。默认情况下,read.table假定列由一个或多个空白字符(tab 空格)分隔。当列以制表符分隔时,指定制表符分隔符(或使用read.delim())才真正有必要,数据列可能包含嵌入的空格......

url <- "https://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data"
bostonHousing <- read.table(url)

似乎工作正常(dec=","也是一个坏主意)