Extract bz2 file in R

前端 未结 5 912
我在风中等你
我在风中等你 2020-12-04 21:39

I have bunch of .csv.bz2 files, which i have to download, extract, and read in R. I downloaded the file and want to extract it to current working directory, the

相关标签:
5条回答
  • 2020-12-04 22:09

    You can use any of these two commands:

    1. read.csv()command: with this command you can directly supply your compressed filename containing csv file.

      read.csv("file.csv.bz2")

    2. read.table() command: This command is generic version of read.csv() command. You can set delimiters and others options that read.csv() automatically sets. You don't need to uncompress the file separately. This command does it automatically for you.

      read.csv("file.csv.bz2", header = TRUE, sep = ",", quote = "\"",...)

    0 讨论(0)
  • 2020-12-04 22:10

    Basically, you need to type:

    library(R.utils)
    bunzip2("dataset.csv.bz2", "dataset.csv", remove = FALSE, skip = TRUE)
    
    dataset <- read.csv("dataset.csv")
    

    See documentation here: bunzip2 {R.utils}.

    0 讨论(0)
  • 2020-12-04 22:22

    According to read.table description, one can read a compressed file directly.

    read.table("file.csv.bz2")
    
    0 讨论(0)
  • 2020-12-04 22:24

    You can make use of the super fast fread which has built-in support for bz2-compressed files

    require(data.table)
    fread("file.csv.bz2")
    
    0 讨论(0)
  • 2020-12-04 22:27

    Like this:

    readcsvbz2file <- read.csv(bzfile("file.csv.bz2"))
    
    0 讨论(0)
提交回复
热议问题