A file .dat
is general and can be structured in text/data form. What happens in your case is that the options default
of read.table
do not read the file correctly. Follow what you can do:
1º) Use readLines
to read the file and understand how it is structured. With this, you can check, for example, if it is necessary to skip lines before reading the file (argument skip
, which may be your case) and what is the manner of separation from it.
Example:
> readLines("https://docs.ufpr.br/~giolo/CE063/Dados/Hemophilia.txt", n=10)
[1] "\"d1\" \"d2\" \"d3\" \"L\" \"R\" \"Low\" \"Medium\" \"High\"" "0 1 0 7 20 1 0 0"
[3] "0 1 0 9 12 0 0 1" "0 1 0 9 20 1 0 0"
[5] "1 0 0 0 25 1 0 0" "0 0 1 57 0 1 0 0"
[7] "0 1 0 23 26 1 0 0" "0 1 0 8 21 1 0 0"
[9] "0 1 0 1 6 0 0 1" "0 0 1 55 0 0 0 0"
Then it is clear that the first row is the header, and the rest the data. Still, the columns are separated by space. That way, to do the reading, it is enough:
> read.table("https://docs.ufpr.br/~giolo/CE063/Dados/Hemophilia.txt", skip = 0, header = T, sep = " ")
d1 d2 d3 L R Low Medium High
1 0 1 0 7 20 1 0 0
2 0 1 0 9 12 0 0 1
3 0 1 0 9 20 1 0 0
4 1 0 0 0 25 1 0 0
5 0 0 1 57 0 1 0 0
6 0 1 0 23 26 1 0 0
7 0 1 0 8 21 1 0 0
8 0 1 0 1 6 0 0 1
9 0 0 1 55 0 0 0 0
10 0 0 1 55 0 0 0 0
If you provide the file .dat
I edit the answer, but the procedure is the same.
Maybe I’ll find
fill = TRUE
.– Rui Barradas