LunaprimRose 2020.03.16
Environment
- MacBook Pro + macOS Catalina 10.15.3
- R 3.6.2 (2019-12-12)
- RStudio Version 1.2.5033
- Typora 0.9.9.32.1 (4191)
- 幕布 1.1.18
R
R是用于统计分析、绘图的语言和操作环境。R是属于GNU系统的一个自由、免费、源代码开放的软件,它是一个用于统计计算和统计制图的优秀工具
Introduction to R
R
is a language and environment for statistical computing and graphics. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. R can be considered as a different implementation of S. There are some important differences, but much code written for S runs unaltered under R.
R
provides a wide variety of statistical (linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, …) and graphical techniques, and is highly extensible. The S language is often the vehicle of choice for research in statistical methodology, and R provides an Open Source route to participation in that activity.
One of R’s strengths is the ease with which well-designed publication-quality plots can be produced, including mathematical symbols and formulae where needed. Great care has been taken over the defaults for the minor design choices in graphics, but the user retains full control.
R
is available as Free Software under the terms of the Free Software Foundation’s GNU General Public License in source code form. It compiles and runs on a wide variety of UNIX platforms and similar systems (including FreeBSD and Linux), Windows and MacOS.
The R environment
R
is an integrated suite of software facilities for data manipulation, calculation and graphical display.
It includes
- an effective data handling and storage facility
- a suite of operators for calculations on arrays, in particular matrices
- a large, coherent, integrated collection of intermediate tools for data analysis
- graphical facilities for data analysis and display either on-screen or on hardcopy, and
- a well-developed, simple and effective programming language which includes conditionals, loops, user-defined recursive functions and input and output facilities
The term “environment” is intended to characterize it as a fully planned and coherent system, rather than an incremental accretion of very specific and inflexible tools, as is frequently the case with other data analysis software.
R
, like S, is designed around a true computer language, and it allows users to add additional functionality by defining new functions. Much of the system is itself written in the R dialect of S, which makes it easy for users to follow the algorithmic choices made. For computationally-intensive tasks, C, C++ and Fortran code can be linked and called at run time. Advanced users can write C code to manipulate R objects directly.
Many users think of R as a statistics system. We prefer to think of it as an environment within which statistical techniques are implemented. R can be extended (easily) via packages. There are about eight packages supplied with the R distribution and many more are available through the CRAN family of Internet sites covering a very wide range of modern statistics.
R
has its own LaTeX-like documentation format, which is used to supply comprehensive documentation, both on-line in a number of formats and in hardcopy.
Download R
The Comprehensive R Archive Network is available at the following URLs, please choose a location close to you.
The Comprehensive R Archive Network
RStudio
Intriduction to RStudio
RStudio is an integrated development environment (IDE) for R , a programming language for statistical computing and graphics. It is available in two formats: RStudio Desktop is a regular desktop application while RStudio Server runs on a remote server and allows accessing RStudio using a web browser.
RStudio IDE Features
RStudio is the premier integrated development environment for R. It is available in open source and commercial editions on the desktop (Windows, Mac, and Linux) and from a web browser to a Linux server running RStudio Server or RStudio Server Pro.
- An IDE that wass built just for R
- Syntax highlighting, code completion, and smart indentation
- Execute R code directly from the source editor
- Quickly jump to function definitions
- Bring your workflow together
- Integrated R help and documentation
- Easily manage multiple working directories using projects
- Workspace browser and data viewer
- Powerful authoring & Debugging
- Interactive debugger to diagnose and fix errors quickly
- Extensive package development tools
- Authoring with Sweave and R Markdown
Download RStudio
-
RStudio Desktop
- Windows 10/8/7 RStudio-1.2.5033.exe
- macOS 10.12+ RStudio-1.2.5033.dmg
- Ubuntu 16 rstudio-1.2.5033-amd64
- Fedora 28/Red Hat 8 rstudio-1.2.5033-x86_64
- RStudio Sever
Configuration
- 设置字体大小
- RStudio
- Tools
- Global Options
- Appearance
- 设置镜像源
- RStudio
- Tools
- Global Options
- Packages
Basic operation
R-project 管理多个 R 工作目录
用R进行数据分析, 不同的分析问题需要放在不同的文件夹中
R 把在命令行定义的变量都保存到工作空间中
退出 R 时可以选择是否保存工作空间
- 显示/设置工作目录
getwd()
setwd()
-
新建 Project
- RStudio
- File
- New Project
打开 Project
显示文件列表
- 显示工作目录下文件
dir()
- 显示指定路径下文件
dir('{path}')
加减乘除
> 1+1
[1] 2
> 1-1
[1] 0
> 1*1
[1] 1
> 1/1
[1] 1
赋值
- 使用
<-
赋值 - 使用
alt -
赋值 - 使用
tab
补全
删除变量
- 使用
rm()
删除变量 - 使用
rm(Variable1,Variable2)
删除多个变量
历史命令
- 使用
history
列出历史命令 - 在
RStudio
中history
部分查看历史命令
Pic
plot(rnorm(50))
boxplot(iris$Sepal.Length~iris$Species,col = c('lightblue','lightyellow','lightpink'))