0

I would like to read a csv file selecting only a subsetting of the available columns. Usually I used to perfom this kind of process using the fread function of the data.table package. I could use read_csv and then select only the columns of interest but I want to do the selection when I read the file.

Is that possible? Have I missed some read_csv options?

4

1 回答 1

3

You can use the col_types() argument of read_csv(), passing cols_only() with the columns you need and their type (also guessable):

read_csv('loadTest.csv', 
         col_types = cols_only('col1' = col_integer(), #col1 is integer
                               'col2' = 'c',           #col2 is character
                               'col8' = col_guess()    #guess type
                               'col10' = '?'           #guess type
                               )
)
于 2017-06-16T09:15:01.987 回答