Day4R语言基础-谢大飞
2020-10-19 本文已影响0人
谢大飞7698
R语言基础
安装R和Rstudio
1.查看电脑用户名是否是英文
打开文件夹,点击文件夹名空白处,即可看到文件的绝对路径(讲道理大概是这样)
确认用户名是否是英文,如果不是就需要改成英文
当Rstudio杠上中文用户名

2.下载R和Rstudio(详情请见 果子学生信 给自己一个全新的R语言环境)
a.下载R语言 https://mirrors.tuna.tsinghua.edu.cn/CRAN/
b.下载Rstudio https://www.rstudio.com/products/rstudio/download/
3.设置Rstudio
下载完之后可以设置Pakage(选择清华镜像)


也可以选择更改一下外观,比如说改成酷酷的黑色模式

4.练手用的图
plot(rnorm(50))
boxplot(iris$Sepal.Length~iris$Species,col = c("lightblue","lightyellow","lightpink"))


plot()函数是R中基本的画x-y两个变量的函数,其用法如下为:plot(x, y, ...)
runif()函数是用来产生随机数的 与 rnorm()函数同样的效果
首先用runif()函数产生了两列随机数:x1,y1,然后用plot()函数直接画图
R语言基本操作
1.使用Project管理工作目录
打开Rstudio,点击新建,然后按照弹出的窗口一次点击之后为它起个名字,最后点击Create Project,就创建成功啦

2.显示文件列表
dir()
list.files()
dir() 函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表
或许list.files()函数相当于Linux系统中的ls?
3.数学运算(加减乘除开平方啥的,按照正常的运算输入法然后回车即可)
3+5
3*5
3/5
3^5
4.赋值
x<- 1+2
赋值符号为<-(小于号加上减号)

5.删除变量
rm() 删除函数(与Linux中删除命令一致,只是变成了函数)
rm(list = ls()) 清空所有变量(或许与Linux中的 rm -r 类似)
当然删除变量的前提是先设置有一些变量

6.列出历史命令
history()
相当于单击右上角的history

9.清空控制台
ctrl+l
今日份思维导图
