A .dat
file is general and can be structured as text / data. What happens in your case is that the options default
of read.table
do not read the file correctly. Here's what you can do:
1º) Use readLines
to read the file and understand how it is structured. So you can check for example if you need to skip lines before reading the file (argument skip
, which may be your case) and how to split 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 becomes clear that the first line is the header, and the others are the data. Still, the columns are separated by space. That way, to read, simply:
> 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 supply the file .dat
I edit the response, but the procedure is the same.