R語(yǔ)言
1.如何下載和安裝R和Rstudio
1).預(yù)防中文用戶名引起的報(bào)麻煩當(dāng)Rstudio杠上中文用戶名
2).下載R和Rstudio
用搜狗微信搜索:“果子學(xué)生信 給自己一個(gè)全新的R語(yǔ)言環(huán)境”
2.認(rèn)識(shí)R和Rstudio
1)什么是R和Rstudio娇澎?
R是一種編程語(yǔ)言,也是統(tǒng)計(jì)計(jì)算和繪圖的環(huán)境稠茂,它匯集了許多函數(shù)茎杂,能夠提供強(qiáng)大的功能奏寨。R語(yǔ)言軟件界面簡(jiǎn)陋椎咧,通常不直接使用忍法,而是用圖形界面的Rstudio。RStudio是免費(fèi)提供的開(kāi)源集成開(kāi)發(fā)環(huán)境(IDE)毅臊。RStudio提供了一個(gè)具有很多功能的環(huán)境理茎,使R更容易使用黑界,是在終端中使用R的絕佳選擇管嬉。
2)設(shè)置字體大小
[圖片上傳失敗...(image-517dbd-1614272544337)]
3)R語(yǔ)言的基本操作
1.用Rproject管理工作目錄
R語(yǔ)言只能和一個(gè)文件夾進(jìn)行互動(dòng),這個(gè)文件夾非常重要朗鸠,做不好就會(huì)導(dǎo)致你的腳本蚯撩、文件、圖片各種亂跑烛占,找不到胎挎。查看這一篇,養(yǎng)成好習(xí)慣: https://mp.weixin.qq.com/s/G-LXN9P2HVLv9v0cvyFJMA
2.顯示文件列表:直接打命令不跟路徑會(huì)顯示哪里忆家?顯示默認(rèn)路徑犹菇,也就是工作目錄。
3.加減乘除:如:1+2 回車
4.賦值:賦值符號(hào)用<-
芽卿,這是小于號(hào)加上減號(hào)揭芍,也可以按Alt加上減號(hào)
x<- 1+2
意思是把1+2的運(yùn)算結(jié)果賦值給x, 賦值后卸例,x會(huì)顯示在右上角的框称杨,Environment里的Value列表里
直接輸入x
回車,就會(huì)把x的值(3)打印到控制臺(tái)上,前面的那個(gè)[1]是結(jié)果的第一個(gè)筷转,不用管他姑原。
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>
括號(hào)要用英文的
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>
相當(dāng)于鼠標(biāo)單擊右上角的history標(biāo)簽
7.清空控制臺(tái)
<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>