介绍
paste0()和paste()函数都可以实现对字符串的连接,paste0是paste的简化版。
paste0()
paste (..., sep = " ", collapse = NULL, recycle0 = FALSE)
-
…
one or more R objects, to be converted to character vectors. -
sep
a character string to separate the terms. Not NA_character_. -
collapse
an optional character string to separate the results. Not NA_character_. -
recycle0
logical indicating if zero-length character arguments should lead to the zero-length character(0) after the sep-phase (which turns into “” in the collapse-phase, i.e., when collapse is not NULL).
实例
> paste0('a','b','c')
[1] "abc"
> paste0(c('a','b'),c('c','d'))
[1] "ac" "bd"
> paste0(c('a','b'),c('c','d'),collapse = '+')
[1] "ac+bd"
paste()
相比于paste0,paste()函数提供了sep参数来制定连接符。文章来源:https://www.toymoban.com/news/detail-645184.html
注意:在对向量间元素进行连接时使用sep参数,在将向量内全部元素连接时需要使用collapse 参数文章来源地址https://www.toymoban.com/news/detail-645184.html
实例
paste('a','b','c')
# [1] "a b c"
paste(c('a','b'),c('c','d'))
# [1] "a c" "b d"
paste(c('a','b'),c('c','d'),sep='+')
# [1] "a+c" "b+d"
paste(c('a','b'),c('c','d'),collapse = '+')
# [1] "a+c" "b+d"
到了这里,关于R语言中的函数25:paste,paste0的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!