简体   繁体   English

无法读取 R 下的.data 文件?

[英]Cannot read .data file under R?

Good morning,早上好,

I need to read the following.data file: https://archive.ics.uci.edu/ml/machine-learning-databases/heart-disease/cleveland.data我需要阅读以下数据文件: https://archive.ics.uci.edu/ml/machine-learning-databases/heart-disease/cleveland.data

For this, I tried without success:为此,我尝试了但没有成功:

f <-file("https://archive.ics.uci.edu/ml/machine-learning-databases/heart-disease/cleveland.data", open="r" ,encoding="UTF-16LE")
data <- read.table(f, dec=",", header=F)

Thank you a lot for help!非常感谢您的帮助!

I would try to use the coatless/ucidata package to access the data.我会尝试使用无涂层/ucidata package 来访问数据。

https://github.com/coatless/ucidata https://github.com/coatless/ucidata

Here you can see how the package loads in the data file and processing:在这里可以看到package是如何在数据文件中加载和处理的:

https://github.com/coatless/ucidata/blob/master/data-raw/heart_disease_build.R https://github.com/coatless/ucidata/blob/master/data-raw/heart_disease_build.R

If you wish to try out the package, you will need devtools installed.如果您想试用 package,则需要安装 devtools。 Here is what you can try:您可以尝试以下方法:

# install.packages("devtools")
devtools::install_github("coatless/ucidata")

# load data
data("heart_disease_cl", package = "ucidata")

# show beginning rows of data
head(heart_disease_cl)

Output Output

  age    sex               cp trestbps chol fbs                       restecg thalach exang oldpeak       slope ca              thal num
1  63   Male   typical angina      145  233   1 probable/definite hypertrophy     150    No     2.3 downsloping  0      fixed defect   0
2  67   Male     asymptomatic      160  286   0 probable/definite hypertrophy     108   Yes     1.5        flat  3            normal   2
3  67   Male     asymptomatic      120  229   0 probable/definite hypertrophy     129   Yes     2.6        flat  2 reversable defect   1
4  37   Male non-anginal pain      130  250   0                        normal     187    No     3.5 downsloping  0            normal   0
5  41 Female  atypical angina      130  204   0 probable/definite hypertrophy     172    No     1.4   upsloping  0            normal   0
6  56   Male  atypical angina      120  236   0                        normal     178    No     0.8   upsloping  0            normal   0

I had found another solution with RCurl :我用RCurl找到了另一个解决方案:

library (RCurl)
download <- getURL("http://archive.ics.uci.edu/ml/machine-learning-databases/00519/heart_failure_clinical_records_dataset.csv")
data <- read.csv (text = download)
head(data)
#Output :
  age anaemia creatinine_phosphokinase diabetes ejection_fraction high_blood_pressure platelets serum_creatinine
1  75       0                      582        0                20                   1    265000              1.9
2  55       0                     7861        0                38                   0    263358              1.1
3  65       0                      146        0                20                   0    162000              1.3
4  50       1                      111        0                20                   0    210000              1.9
5  65       1                      160        1                20                   0    327000              2.7
6  90       1                       47        0                40                   1    204000              2.1
  serum_sodium sex smoking time DEATH_EVENT
1          130   1       0    4           1
2          136   1       0    6           1
3          129   1       1    7           1
4          137   1       0    7           1
5          116   0       0    8           1
6          132   1       1    8           1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM