R包安裝薪介,有多種方法:包括install.package裝載和直接下載R包拖進(jìn)文件夾
dplyr包用法不是很熟悉祠饺,重點(diǎn)寫一下:
test <- iris[c(1:2,51:52,101:102),]
新增一列:mutate(test, new = Sepal.Length * Sepal.Width)
其中new即是新一列數(shù)據(jù)的名字篩選列的功能感覺(jué)不是特別好用,和[汁政,n]用法類似
select(test,c(n,m))或者c(n,m)換成列名也可filter功能蠻好用的道偷,與which的用法類似,但更簡(jiǎn)單
filter(test, Species == "setosa")
filter(test, Species == "setosa"&Sepal.Length > 5 ) 和which函數(shù)一致记劈,表示且用&
filter(test, Species %in% c("setosa","versicolor"))arrange()函數(shù)對(duì)數(shù)據(jù)進(jìn)行排序(是針對(duì)某一列的數(shù)據(jù)勺鸦,對(duì)整個(gè)表格改變順序)
arrange(test, Sepal.Length)默認(rèn)的是從小到大,如果要變成從大到小換成desc(Sepal.Length)即可%>%管道操作目木,其實(shí)不太明白
count(test,Species)統(tǒng)計(jì)出現(xiàn)次數(shù)
連接函數(shù)换途,其實(shí)不如用merge函數(shù),但反連接:返回?zé)o法與y表匹配的x表的所記錄anti_join
anti_join(x = test2, y = test1, by = 'x')
test1 <- data.frame(x = c(1,2,3,4), y = c(10,20,30,40))