说明:斜体为R语言代码
01确保R软件处于可使用状态
R软件为开源软件,下载安装成功后,若出现以下提示,则表明安装成功,处于可试用状态。
R version 3.5.1 (2018-07-02) – “Feather Spray”
Copyright © 2018 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type ‘license()’ or ‘licence()’ for distribution details.
R is a collaborative project with many contributors.
Type ‘contributors()’ for more information and
‘citation()’ on how to cite R or R packages in publications.
Type ‘demo()’ for some demos, ‘help()’ for on-line help, or
‘help.start()’ for an HTML browser interface to help.
Type ‘q()’ to quit R.
[Workspace loaded from ~/.RData]
>
安装成功后,R Console工作区域每行以 > 开头。
02获取工作目录
若要在当前目录下读取文件,需要获取当前的工作目录。
获取工作目录的函数: getwd()
例:
> getwd()
[1] “C:/Users/Administrator/Documents”
03设置/改变工作目录
为了方便读取本地文件,需要将工作目录设置为目标文件所在的存储路径。
设置工作目录的函数: setwd(“工作目录的文件夹路径”).
注意:工作目录的文件夹路径需要用 英文双引号 包围。
例:将工作目录设置为E盘下的DataAnalysis文件夹
*> setwd(“E:/DataAnalysis”)
getwd()
[1] “E:/DataAnalysis”*