生信菜鸟团
如有问题或建议,请公众号留言
library(tidyverse)
library(stringr)
str_length(c('a', 'R for data science', NA))
#> [1] 1 18 NA
str_c('x', 'y')
#> [1] 'xy'
str_c('x', 'y', 'z')
#> [1] 'xyz'
str_c('x', 'y', sep = ', ')
#> [1] 'x, y'
str_c(c('x', 'y', 'z'), collapse = ', ')
[1] 'x, y, z'
> str_c(c('x', 'y', 'z'), sep = ', ')
[1] 'x' 'y' 'z'
> str_c(c('x', 'y'), sep = ', ')
[1] 'x' 'y'
> str_c('x', 'y', sep = ', ')
[1] 'x, y'
x <>'Apple', 'Banana', 'Pear')
str_sub(x, 1, 3)
#> [1] 'App' 'Ban' 'Pea'
# negative numbers count backwards from end
str_sub(x, -3, -1)
#> [1] 'ple' 'ana' 'ear'
str_sub('a', 1, 5)
#> [1] 'a'
str_sub('a', 1, 5)
#> [1] 'a'
x <>'apple', 'banana', 'pear')
str_view(x, 'an')
apple
banana
pear
x <>'apple', 'banana', 'pear')
str_view(x, '.a.')
apple
banana
pear
str_view(fruit, '(..)\\1', match = TRUE)
banana
coconut
cucumber
jujube
papaya
salal berry
联系客服