smudo78
smudo78

Reputation: 478

Access column after reading .csv file with fread

when I read a .csv file with read.csv like this

df1 <- read.csv("a.csv")

and I access a single column like this

df1[,1]

I get the expected column vector.


But in contrast, if i read the .csv with fread (from the library data.table)

df2 <- fread("a.csv")

and access a single column

df2[,1]

It just returns

1

Can somebody explain, why I can't access the column vector by its index, when I read the csv with fread?

Upvotes: 0

Views: 1062

Answers (1)

Sixiang.Hu
Sixiang.Hu

Reputation: 1019

According to the ?fread in data.table, you will find a parameter data.table:

data.table TRUE returns a data.table. FALSE returns a data.frame.

By default, data.table is TRUE, hence a data.table is created.

If you prefer the df2[,1] style, using:

df2 <- fread("a.csv",data.table=FALSE)

Upvotes: 1

Related Questions