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.
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.
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.
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.
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.
X <- as.matrix(fread("bigmatrix.csv"),rownames=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With