Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to indicate row.names=1 using fread() in data.table?

Tags:

I want to consider the first column in my .csv file as a sequence of rownames. Usually I used to do the following:

read.csv("example_file.csv", row.names=1)

But I want to do this with the fread() function in the data.table R package, as it runs very quickly.

like image 724
Koundy Avatar asked Jun 26 '14 07:06

Koundy


People also ask

How do you set a row name in a data frame?

A data frame's rows can be accessed using rownames() method in the R programming language. We can specify the new row names using a vector of numerical or strings and assign it back to the rownames() method. The data frame is then modified reflecting the new row names.

What is use of row names ()?

The rownames() and colnames() functions in R are used to obtain or set the names of the row and column of a matrix-like object, respectively.

What is the data type of the row names of a data frame?

Row names are currently allowed to be integer or character, but for backwards compatibility (with R <= 2.4. 0) row. names will always return a character vector.

What is fread function in R?

The fread() function reads up to count items of size length from the input stream and stores them in the given buffer. The position in the file increases by the number of bytes read.


1 Answers

X <- as.matrix(fread("bigmatrix.csv"),rownames=1)
like image 80
ikwee Avatar answered Sep 17 '22 00:09

ikwee