导读:R语言有许多种方法去获取数据,最常用的是读取CSV文件。

read.tableread.csvread.tableread.tablesep,read.tabledata.frame
read.table
read.table

http://www.jaredlander.com/data/TomatoFirst.csv

head
fileheadsep
headersed\t;
stringAsFactorsFALSETRUEfactor
stringAsFactorsdata.frame
read.tablequotecolClasses
read.csvread.tablesepdec

▲表6-1 读取大文本文件的函数及其默认参数

read.tableread_delimfreadreadrdata.tableread_delimfreadfactor

01 read_delim函数

readrread_delimcol_namesTRUE
read_delimhead.read_delimreadrtibbledata.frametibble
read_delimread.tablestringAsFactorsFALSEread_csvread_csv2read_tsvread.table,;\t
tbl_dftbldata.frametbldata.framedplyr
readrread_delimread_csvread_tsv

02 fread函数

data.tablefreadheadersepstringAsFactorsFALSE

这里也可以使用head函数查看前几行数据:

read.tabledata.tabledata.tabledata.framedata.frame
read_delimfreaddplyrdata.table

本文摘编自《R语言:实用数据分析和可视化技术》(原书第2版),经出版方授权发布。