鏡像設(shè)置
file.edit('~/.Rprofile')
把下面代碼加入配置文件中
options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/")
查看
options()$repos
options()$BioC_mirror
>options()$repos
CRAN
"https://mirrors.tuna.tsinghua.edu.cn/CRAN/"
> options()$BioC_mirror
[1] "https://mirrors.ustc.edu.cn/bioc/"
數(shù)據(jù)框操作R包 dplyr
- 此包為數(shù)據(jù)框的操作提供了許多便捷的操作
install.packages("dplyr")
dplyr provides a flexible grammar of data manipulation
library(dplyr)
test <- iris[c(1:2,51:52,101:102),]
#加一列
test$new=test$Sepal.Length*test$Sepal.Width
mutate(test,t=Sepal.Length*Sepal.Width)
#按列
select(test,1)
head(test[,1])
head(test[,c(2,3)])
select(test,Petal.Width)
test[,c("Petal.Width")]
head(test[,colnames(test)=="Petal.Width"])
#按行
filter(test,Species == "setosa")
filter(test,Species == "setosa"&Sepal.Length > 5)
filter(test,Species %in% c("setosa","versicolor"))
#arrange排序
arrange(test,Sepal.Length)
arrange(test,desc(Sepal.Length))
#匯總
summarise(test,mean(Sepal.Length))
group_by(test,Species)
summarise(group_by(test, Species),mean(Sepal.Length), sd(Sepal.Length))
##實(shí)用技能
#計(jì)算unique值
count(test,Species)
#處理關(guān)系數(shù)據(jù)
test1 <- data.frame(x = c('b','e','f','x'),
z = c("A","B","C",'D'),
stringsAsFactors = F)
test2 <- data.frame(x = c('a','b','c','d','e','f'),
y = c(1,2,3,4,5,6),
stringsAsFactors = F)
#半連接,返回與Y匹配的所有x
semi_join(x = test1, y = test2, by = 'x')
#全連接
full_join( test1, test2, by = 'x')
#內(nèi)連接:交集
inner_join(test1, test2, by = "x")