R: Is there a way to subset a file while reading

后端 未结 3 337
甜味超标
甜味超标 2021-01-14 14:10

I have a huge .csv file, its size is ~ 1.4G and reading with read.csv takes time. There are several variables in that file and all i want is to ext

3条回答
  •  不思量自难忘°
    2021-01-14 14:57

    I would say that most of the time you can probably just read in the entire file, and then subset within R:

    df <- read.csv(file="path/to/your/file.csv", header=TRUE)
    df.x <- df[df$Variables=='x', ]
    

    R operates completely in memory, so an exception to what I said above might occur if you have a file whose total size is so massive that it cannot fit into memory, but for some reason the subset of interest can.

提交回复
热议问题