5 handy options in R data.table’s fread

Like all features in the knowledge.desk R bundle, fread is speedy. Extremely speedy. But there’s extra to fread than speed. It has several beneficial features and alternatives when importing exterior knowledge into R. Here are 5 of the most practical.

Notice: If you’d like to observe along, obtain the New York Situations CSV file of daily Covid-19 situations by U.S. county at https://github.com/nytimes/covid-19-knowledge/raw/learn/us-counties.csv.

Use fread’s nrows solution

Is your file large? Would you like to analyze its construction ahead of importing the whole point – without having to open it in a textual content editor or Excel? Use fread’s nrows solution to import only a portion of a file for exploration.

The code underneath imports just the initially ten rows of the CSV.

mydt10 <- fread("us-counties.csv", nrows = 10)

If you just want to see column names without any knowledge at all, you can use nrows =

Use fread’s pick solution

When you know the file construction, you can pick out which columns to import. fread’s pick solution lets you decide columns you want to continue to keep. pick can take a vector of either column names or column-placement figures. If names, they need to be in quotation marks, like most vectors of character strings:

Copyright © 2020 IDG Communications, Inc.