Day4-Luke
R语言
1.如何下载和安装R和Rstudio
1).预防中文用户名引起的报麻烦当Rstudio杠上中文用户名
2).下载R和Rstudio
用搜狗微信搜索:“果子学生信 给自己一个全新的R语言环境”
2.认识R和Rstudio
1)什么是R和Rstudio?
R是一种编程语言,也是统计计算和绘图的环境,它汇集了许多函数,能够提供强大的功能。R语言软件界面简陋,通常不直接使用,而是用图形界面的Rstudio。RStudio是免费提供的开源集成开发环境(IDE)。RStudio提供了一个具有很多功能的环境,使R更容易使用,是在终端中使用R的绝佳选择。
2)设置字体大小
[图片上传失败...(image-517dbd-1614272544337)]
3)R语言的基本操作
1.用Rproject管理工作目录
R语言只能和一个文件夹进行互动,这个文件夹非常重要,做不好就会导致你的脚本、文件、图片各种乱跑,找不到。查看这一篇,养成好习惯: https://mp.weixin.qq.com/s/G-LXN9P2HVLv9v0cvyFJMA
2.显示文件列表:直接打命令不跟路径会显示哪里?显示默认路径,也就是工作目录。
3.加减乘除:如:1+2 回车
4.赋值:赋值符号用<-
,这是小于号加上减号,也可以按Alt加上减号
x<- 1+2
意思是把1+2的运算结果赋值给x, 赋值后,x会显示在右上角的框,Environment里的Value列表里
直接输入x
回车,就会把x的值(3)打印到控制台上,前面的那个[1]是结果的第一个,不用管他。
5.删除变量
<pre mdtype="fences" cid="n72" lang="java" class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">a<-3
b <- 1
c <- 4
u <- 5+6
rm(b)
rm(u,c)
rm(list = ls())#清空所有变量</pre>
括号要用英文的
6.列出历史命令
<pre mdtype="fences" cid="n77" lang="java" class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">history()</pre>
相当于鼠标单击右上角的history标签
7.清空控制台
<pre mdtype="fences" cid="n82" lang="k=java" class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">快捷键ctrl+l</pre>