復(fù)習(xí)
- 標(biāo)量:數(shù)字或者一串字符
向量:c(數(shù)字或者字符串)
幾種類型:
c(1,2,3) 1:10 seq(1,10,by=0.5) rep (1:3,times=2)
- 賦值 字母,數(shù)字,字符串,單詞等均可賦值,新的賦值可代替舊的賦值
- 元素提取 例如 x[],用中括號
- 數(shù)據(jù)框讀取:read.table() 括號內(nèi)是 file=" txt",sep= '' '' ,header=T
read.csv(' txt') colnames() rownames()
5 數(shù)據(jù)框?qū)С?write.table( X,file=" txt",sep=' ',quote=F)
- 保存和加載: save.image(file="bioinfoplanet.RData"),save(X,file= "test.RData") load(test.RData)
day6
install.package(包),
options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/")
install.packages("dplyr")
library(dplyr)
iris示例
賦值test<-iris[c(1:2,51:52,101:102)]
dplyr的五個基礎(chǔ)函數(shù)
- mutate()
例如mutate(test, new = Sepal.Length * Sepal.Width)
2.select()
例如: select(test,c(1,5)).select(test,Sepal.Length) select(test, Petal.Length, Petal.Width) - filter()
例如 ilter(test, Species == "setosa") - arrange()
例如:arrange(test, Sepal.Length)
arrange(test, desc(Sepal.Length))
desc是從大到小
5.summarise() 匯總
group_by() 更實用
dplyr 兩個實用技能
- %>% 快捷鍵 shift+ctr+m 管道符號
test %>%
group_by(Species) %>%
summarise(mean(Sepal.Length), sd(Sepal.Length)) - count統(tǒng)計列表 count(test,Species)
- dplyr 處理關(guān)系數(shù)據(jù)
賦值 test1 test2
內(nèi)連:inner_join(test1, test2, by = "x")
左連:left_join(test1, test2, by = 'x')
全連:full_join( test1, test2, by = 'x')
半連:semi_join(x = test1, y = test2, by = 'x')
反連:anti_join(x = test2, y = test1, by = 'x')
合并:bind_rows(test1, test2) bind_cols(test1, test3)
fplyr函數(shù)
dplyr操作
summarise
count
dplyr關(guān)系處理
R包.png