drjrm3 drjrm3 - 1 year ago 151
R Question

Read file as matrix in fread

I am using

but my file does not have any header names at all. It is a raw file with just the information I need.

If I use
A <- as.matrix(read.table(fname))
then I get all 1000 rows, but it is slower. However, when I use
A <- as.matrix(fread(fname))
it is faster but only returns 999 rows.

Is there a way to get
to return everything just like
would? I have searched the documentation but am unable to find anything.

Answer Source

As Gregor mentioned, fread has an argument "header" which defaults to true if all of the entries in the first row are character type fields. When you ran fread it most likely assumed the first row of data contained column names and the remaining 999 rows were data. I couldn't say for sure without seeing the data you're importing, though.

This should do the trick for you:

    A <- as.matrix(fread(fname, header = F))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download