R环境
如果没有安装R可以点这里下载安装
- Linux和MacOS玩家可以通过终端输入
R
, Windows玩家需要输入R.exe
进入R环境
Windows玩家不仅需要安装R,还需要手动配置环境变量
- 进入R环境,可以看到终端前出现了
>
标识符,这时输入的语句会被当成R语言执行 - 输入
q()
并按下回车即可退出R环境
获取帮助
R语言不依赖于第三方工具即可查找提示
例如想要获取lapply
的帮助可以这样做
help(lappy)
?lappy
可以得到以下输出
Description
lapply returns a list of the same length as X, each element of which is the result of applying FUN to the corresponding element of X.
sapply is a user-friendly version and wrapper of lapply by default returning a vector, matrix or, if simplify = "array", an array if appropriate, by applying simplify2array(). sapply(x, f, simplify = FALSE, USE.NAMES = FALSE) is the same as lapply(x, f).
vapply is similar to sapply, but has a pre-specified type of return value, so it can be safer (and sometimes faster) to use.
replicate is a wrapper for the common use of sapply for repeated evaluation of an expression (which will usually involve random number generation).
simplify2array() is the utility called from sapply() when simplify is not false and is similarly called from mapply().
...
这两种方式获得的结果一样,没有优劣之分
有时遇到有些符号的用法不清楚,这时可以使用help("arg")
,注意,这里参数需要双引号
例如获取<-
的帮助可以这样做
help("<-")
可以得到以下输出
Description
Assign a value to a name.
Usage
x <- value
x <<- value
value -> x
value ->> x
x = value
...