Reading raw data and turning it into a data structure
As mentioned before, part of what makes iotools fast is that it separates reading data from the hard drive from converting the binary data it into a data.frame or matrix. Data in their binary format are copied from the hard drive into memory as raw objects. These raw objects are then passed to optimized functions that turn them into data.frame or matrix objects.
In this exercise, you'll learn how to separate reading data from the disk (using the readAsRaw() function), and then convert the raw binary data into a matrix or data.frame (using the mstrsplit() and dstrsplit() functions).
Bu egzersiz
Scalable Data Processing in R
kursunun bir parçasıdırEgzersiz talimatları
- Read
"mortgage-sample.csv"as a raw vector. - Convert the raw vector contents to a
matrixof integers. - Convert the raw vector contents to a
data.framewith 16 integer columns.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Read mortgage-sample.csv as a raw vector
raw_file_content <- ___("mortgage-sample.csv")
# Convert the raw vector contents to a matrix
mort_mat <- ___(___, sep = ",", type = ___, skip = 1)
# Look at the first 6 rows
head(mort_mat)
# Convert the raw file contents to a data.frame
mort_df <- ___(___, sep = ",", col_types = rep("integer", 16), skip = 1)
# Look at the first 6 rows
head(mort_df)