前言

这是李东风的《R语言教程》的草稿, 还在更新中。 错漏之处难免,欢迎指出错误或提出改进意见。

相关下载:

书中的数学公式使用MathJax库显示, 下面是数学公式测试。 如果数学公式显示的中文不正常, 在浏览器中用鼠标右键单击中文公式, 在弹出的菜单中选择Math Settings--Math Renderer选HTML-CSS或SVG即可。

公式测试: \[ f(x) = \sum_{k=0}^\infty \frac{x^k}{k!} \]

中文公式测试: \[ \text{相对误差} = \frac{a - A}{A} \]

使用本教程必须安装的软件包:

  • tidyverse
  • bookdown
  • xtable
  • microbenchmark

本教程中用到的软件包列表(更新R软件后可以在一个基本R中运行如下命令):

pkgs <- c(
  "assertthat", 
  "backports", "base64enc", "BH", "bindr", "bindrcpp", "bookdown", "broom", 
  "callr", "car", "cellranger", "cli", "clipr", "clorspace", 
  "cowplot", "crayon", "curl", 
  "DBI", "dbplyr", "dichromat", "digest", "dplyr", 
  "evaluate", 
  "forcats", 
  "ggplot2", "ggrepel", "glue", "gtable", 
  "haven", "highr", "hms", "htmltools", "httr", 
  "jsonlite", 
  "knitr", 
  "labeling", "lazyeval", "lubridate", 
  "magrittr", "markdown", "microbenchmark", "mime", "mnormt", "modelr", "munsell", 
  "NHANES",
  "openssl", 
  "pillar", "pkgconfig", "plogr", "plyr", "psych", "purr", 
  "R6", "RColorBrewer", "Rcpp", "readr", "readxl", 
  "rematch", "reprex", "reshape2", "rlang", "rmarkdown", 
  "rprojroot", "rstudioapi", "rvest", 
  "scales", "selectr", "socviz", "stringi", "stringr", 
  "tibble", "tidyr", "tidyselect", "tidyverse", 
  "utf8", 
  "viridisLite", 
  "whisker", 
  "xml2", "xtable",
  "yaml"
)
install.packages(unique(pkgs))

编译本教程所用的R软件环境:

devtools::session_info()
## - Session info ---------------------------------------------------------------
##  setting  value                         
##  version  R version 4.0.0 (2020-04-24)  
##  os       Windows 10 x64                
##  system   x86_64, mingw32               
##  ui       RTerm                         
##  language (EN)                          
##  collate  Chinese (Simplified)_China.936
##  ctype    Chinese (Simplified)_China.936
##  tz       Asia/Taipei                   
##  date     2020-06-06                    
## 
## - Packages -------------------------------------------------------------------
##  package     * version date       lib source        
##  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.0)
##  backports     1.1.7   2020-05-13 [1] CRAN (R 4.0.0)
##  bookdown      0.19    2020-05-15 [1] CRAN (R 4.0.0)
##  callr         3.4.3   2020-03-28 [1] CRAN (R 4.0.0)
##  cli           2.0.2   2020-02-28 [1] CRAN (R 4.0.0)
##  crayon        1.3.4   2017-09-16 [1] CRAN (R 4.0.0)
##  desc          1.2.0   2018-05-01 [1] CRAN (R 4.0.0)
##  devtools      2.3.0   2020-04-10 [1] CRAN (R 4.0.0)
##  digest        0.6.25  2020-02-23 [1] CRAN (R 4.0.0)
##  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.0)
##  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.0)
##  fansi         0.4.1   2020-01-08 [1] CRAN (R 4.0.0)
##  fs            1.4.1   2020-04-04 [1] CRAN (R 4.0.0)
##  glue          1.4.1   2020-05-13 [1] CRAN (R 4.0.0)
##  htmltools     0.4.0   2019-10-04 [1] CRAN (R 4.0.0)
##  knitr         1.28    2020-02-06 [1] CRAN (R 4.0.0)
##  magrittr      1.5     2014-11-22 [1] CRAN (R 4.0.0)
##  memoise       1.1.0   2017-04-21 [1] CRAN (R 4.0.0)
##  pkgbuild      1.0.8   2020-05-07 [1] CRAN (R 4.0.0)
##  pkgload       1.1.0   2020-05-29 [1] CRAN (R 4.0.0)
##  prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.0)
##  processx      3.4.2   2020-02-09 [1] CRAN (R 4.0.0)
##  ps            1.3.3   2020-05-08 [1] CRAN (R 4.0.0)
##  R6            2.4.1   2019-11-12 [1] CRAN (R 4.0.0)
##  Rcpp          1.0.4.6 2020-04-09 [1] CRAN (R 4.0.0)
##  remotes       2.1.1   2020-02-15 [1] CRAN (R 4.0.0)
##  rlang         0.4.6   2020-05-02 [1] CRAN (R 4.0.0)
##  rmarkdown     2.2     2020-05-31 [1] CRAN (R 4.0.0)
##  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 4.0.0)
##  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.0)
##  stringi       1.4.6   2020-02-17 [1] CRAN (R 4.0.0)
##  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.0.0)
##  testthat      2.3.2   2020-03-02 [1] CRAN (R 4.0.0)
##  usethis       1.6.1   2020-04-29 [1] CRAN (R 4.0.0)
##  withr         2.2.0   2020-04-20 [1] CRAN (R 4.0.0)
##  xfun          0.14    2020-05-20 [1] CRAN (R 4.0.0)
##  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.0)
## 
## [1] D:/R/R-4.0.0/library