April 26, 2024

Motemapembe

The Internet Generation

5 handy options in R data.table’s fread

Like all features in the info.table R deal, fread is speedy. Quite speedy. But there is much more to fread than velocity. It has a number of beneficial characteristics and options when importing exterior info into R. In this article are five of the most valuable.

Observe: If you’d like to follow along, download the New York Situations CSV file of every day Covid-19 cases by U.S. county at https://github.com/nytimes/covid-19-info/uncooked/master/us-counties.csv.

Use fread’s nrows selection

Is your file big? Would you like to take a look at its framework right before importing the full detail – without acquiring to open it in a text editor or Excel? Use fread’s nrows selection to import only a portion of a file for exploration.

The code down below imports just the to start with 10 rows of the CSV.

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

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

Use fread’s pick selection

The moment you know the file framework, you can opt for which columns to import. fread’s pick selection allows you pick columns you want to keep. pick normally takes a vector of possibly column names or column-position numbers. If names, they need to be in quotation marks, like most vectors of character strings:

Copyright © 2020 IDG Communications, Inc.