介紹
paste0()和paste()函數(shù)都可以實(shí)現(xiàn)對(duì)字符串的連接,paste0是paste的簡(jiǎn)化版。
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).
實(shí)例
> 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()函數(shù)提供了sep參數(shù)來(lái)制定連接符。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-645184.html
注意:在對(duì)向量間元素進(jìn)行連接時(shí)使用sep參數(shù),在將向量?jī)?nèi)全部元素連接時(shí)需要使用collapse 參數(shù)文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-645184.html
實(shí)例
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"
到了這里,關(guān)于R語(yǔ)言中的函數(shù)25:paste,paste0的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!