r - Convert a data read in by fread function to data.frame -
assume have sample csv file has 3 rows , 4 columns. looks following:
name1 name2 name3 name4 11 12 13 14 21 22 23 24 31 32 33 34
i read in using fread()
(i using small sample illustration purpose):
data <- fread(sample.csv, stringsasfactors=false)
then
class(data)
it return
[1] "data.table" "data.frame"
i want see first element of fourth column, tried
data[1,4]
but returns 4 (which guess index of column).
interestingly, when call following
data[1,]
or
data[1]
it returns first row.
so did
data <- data.frame(data)
to convert data data frame.
my questions:
1. since initial data has 2 classes, there way me choose 1 class , 'drop' other? in case, want use data data frame.
2. in general, if data has more 1 class, may choose 1 class keep? instance, as.posixct()
return object 2 classes ("posixct" "posixt"). if want keep 1 of classes? function works purpose in generic way?
if want use fread , want data data frame set property of data.table
false. default true.
a data.table
default. data.frame
when argument data.table=false;
e.g.
options(datatable.fread.datatable=false).
see documentation of r fread reference. https://www.rdocumentation.org/packages/data.table/versions/1.10.4-2/topics/fread
Comments
Post a Comment