R语言中提供了许多用来整合和重塑数据的强大方法
在整合数据时,往往将多组观测值替换为根据这些观测值计算的描叙性统计量
在重塑数据时,则会通过修改数据的结构(行和列)来决定数据的组织方式
使用SQL语句操作数据(*)
- 虽然在R语言中有很多优秀的函数,如aggregate和daply可以对数据框统计,但sql功能强大,不仅能实现数据的清洗、统计、运算,还可以实现数据存储、控制、定义和调用
- library(sqldf)
示例:
# 安装sqldf包
install.packages("sqldf")
# 运行结果:
# WARNING: Rtools is required to build R packages but is not currently installed. Please # download and install the appropriate version of Rtools before proceeding:
#
# https://cran.rstudio.com/bin/windows/Rtools/
# Installing package into ‘C:/Users/Admin/Documents/R/win-library/3.6’
# (as ‘lib’ is unspecified)
# also installing the dependencies ‘ellipsis’, ‘glue’, ‘bit’, ‘rlang’, ‘vctrs’, ‘digest’, ‘bit64’, ‘blob’, ‘memoise’, ‘pkgconfig’, ‘Rcpp’, ‘BH’, ‘plogr’, ‘gsubfn’, ‘proto’, ‘RSQLite’, ‘DBI’, ‘chron’
#
# 试开URL’https://cran.rstudio.com/bin/windows/contrib/3.6/ellipsis_0.3.0.zip'
# Content type 'application/zip' length 44575 bytes (43 KB)
# downloaded 43 KB
#
# 试开URL’https://cran.rstudio.com/bin/windows/contrib/3.6/glue_1.4.0.zip'
# Content type 'application/zip' length 158233 bytes (154 KB)
# downloaded 154 KB
#
# 试开URL’https://cran.rstudio.com/bin/windows/contrib/3.6/bit_1.1-15.2.zip'
# Content type 'application/zip' length 252475 bytes (246 KB)
# downloaded 246 KB
#
# 试开URL’https://cran.rstudio.com/bin/windows/contrib/3.6/rlang_0.4.5.zip'
# Content type 'application/zip' length 1131356 bytes (1.1 MB)
# downloaded 1.1 MB
#
# 试开URL’https://cran.rstudio.com/bin/windows/contrib/3.6/vctrs_0.2.4.zip'
# Content type 'application/zip' length 1027328 bytes (1003 KB)
# downloaded 1003 KB
#
# 试开URL’https://cran.rstudio.com/bin/windows/contrib/3.6/digest_0.6.25.zip'
# Content type 'application/zip' length 249452 bytes (243 KB)
# downloaded 243 KB
#
# 试开URL’https://cran.rstudio.com/bin/windows/contrib/3.6/bit64_0.9-7.zip'
# Content type 'application/zip' length 551485 bytes (538 KB)
# downloaded 538 KB
#
# 试开URL’https://cran.rstudio.com/bin/windows/contrib/3.6/blob_1.2.1.zip'
# Content type 'application/zip' length 47627 bytes (46 KB)
# downloaded 46 KB
#
# 试开URL’https://cran.rstudio.com/bin/windows/contrib/3.6/memoise_1.1.0.zip'
# Content type 'application/zip' length 36855 bytes (35 KB)
#