您好我正在尝试从网址导入数据: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")
答案 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=","
也是一个坏主意)