rstudio导入数据
I have completed two courses at DataCamp that introduced me to the concept of importing data into R. There are numerous ways to import the data. I would like to discuss in detail some of the methods that I learned in the course. Let’s get started.
我已经在DataCamp完成了两门课程,向我介绍了将数据导入R的概念。有很多方法可以导入数据。 我想详细讨论我在本课程中学到的一些方法。 让我们开始吧。
Data can come from many sources. Some of the most common ones are
数据可以来自许多来源。 一些最常见的是
- Flat Files — CSV, txt, tsv, etc 平面文件-CSV,txt,tsv等
- Data from Excel 来自Excel的数据
- DataBases — Postgresql, Mysql, etc 数据库-Postgresql,Mysql等
- Web 网页
- Statistical Softwares — SAS, SPSS, STATA 统计软件-SAS,SPSS,STATA
平面文件 (Flat-Files)
What is a flat-file?
什么是平面文件?
According to Wikipedia, A flat-file database is a database stored in a file called a flat-file. Records follow a uniform format, and there are no structures for indexing or recognizing relationships between records. The file is simple. A flat file can be a plain text file or a binary file.
根据Wikipedia的说法, 平面文件数据库是存储在称为Flat文件的文件中的数据库。 记录遵循统一的格式,并且没有索引或识别记录之间关系的结构。 该文件很简单。 平面文件可以是纯文本文件或二进制文件。
Listed below are some of the packages that will help you to deal while working with the Flat-Files in R.
下面列出了一些软件包,可以帮助您在使用R中的Flat-Files时进行处理。
UTIL
UTIL
This package is loaded by default when you load R.
默认情况下,在加载R时会加载此软件包。
read.table()
: Main function. Reads a file in table format and creates a data frame from it. It offers many arguments to classify the incoming data.read.table()
:主要功能。 读取表格式的文件并从中创建数据框。 它提供了许多参数来分类传入的数据。read.csv()
: Wrapper function for read.table(). Used to read comma-separated (CSV) files.read.csv()
:read.table()的包装函数。 用于读取逗号分隔(CSV)文件。read.delim()
: Wrapper Function used to read tab-separated files. read.delim() is used if the numbers in your file use periods(.) as decimals.read.delim()
:包装函数,用于读取制表符分隔的文件。 如果文件中的数字使用点号(。)作为小数,则使用read.delim()。read.csv2()
: read.csv() and read.csv2() are identical. The only difference is that they are set up depending on whether you use periods or commas as decimal points in numbers.read.csv2()
:read.csv()和read.csv2()相同。 唯一的区别是,它们的设置取决于您使用句点还是逗号作为数字的小数点。read.delim2()
: read.delim2 is used when the numbers in your file use commas(,) as decimals.read.delim2()
:当文件中的数字使用逗号(,)作为小数时,将使用read.delim2。

Specialized Packages
专业套餐
readr
阅读器
This package makes our life easier. It is fast, convenient, and more efficient than the utils package. I tend to use this always.
这个包裹使我们的生活更轻松。 它比utils包更快,更方便且更高效。 我倾向于总是使用它。
read_r supports seven file formats with seven functions:
read_r支持具有七个功能的七种文件格式:
read_csv()
: comma-separated (CSV) filesread_csv()
:逗号分隔(CSV)文件read_tsv()
: tab-separated filesread_tsv()
:制表符分隔的文件read_delim()
: general delimited filesread_delim()
:常规定界文件read_fwf()
: fixed-width files