第一部分:字符串
1 检测字符串长度
x = "The birch canoe slid on the smooth planks."
str_length(x)
[1] "The birch canoe slid on the smooth planks."
length(x)
[1] 1
2 字符串拆分
str_split(x," ")
[[1]]
"The" "birch" "canoe" "slid" "on" "the" "smooth" "planks."
x2 = str_split(x," ")[[1]];x2
[1]"The" "birch" "canoe" "slid" "on" "the" "smooth" "planks."
3 按位置提取字符串
str_sub(x,5,9)
[1]"birch"
str_sub(x,6,9)
[1]"irch"
4 字符检测
str_detect(x2,"h")
[1] TRUE TRUE FALSE FALSE FALSE TRUE TRUE FALSE
str_starts(x2,"T")
[1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
str_ends(x2,"e")
[1] TRUE FALSE TRUE FALSE FALSE TRUE FALSE FALSE
5 字符替换
x2
[1] "The" "birch" "canoe" "slid" "on" "the" "smooth" "planks."
str_replace(x2,"o","A")
[1] "The" "birch" "canAe" "slid" "An" "the" "smAoth" "planks."
str_replace_all(x2,"o","A")
[1] "The" "birch" "canAe" "slid" "An" "the"
[7] "smAAth" "planks."
6 字符删除
x
[1]"The birch canoe slid on the smooth planks."
str_remove(x," ")
[1] "Thebirch canoe slid on the smooth planks."
str_remove_all(x," ")
[1] "Thebirchcanoeslidonthesmoothplanks."
arrange()
arrange()
test = iris
arrange(test,Sepal.Length)
arrange(test,desc(Sepal.Length))
#按降序
distinct() 去重复
distinct(test, Species, .keep)
if不可以放置多个布尔逻辑
ifelse可以安置多个布尔逻辑
对矩阵、数据框循环 apply函数
x
apply(x,1,sum)
挑选出表达矩阵里方差最大的1000个基因
load("test2.Rdata")
apply(test,1,var)
sort(apply(test,1,var))
tail(sort(apply(test,1,var)),1000)
列表的隐式循环 lapply,结果输出是列表
lapply
直接对lapply的结果进行简化,sapply
sapply
inner_join 交集,取交集的函数,和merge类似
left_join, 保留左侧表的全部数据,右侧做补充,补充不上则自动填充NA
right_join
full_join 全连接
一些补充函数
dir
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。