R语言中的函数25:paste,paste0

文章目录

介绍

paste0()和paste()函数都可以实现对字符串的连接,paste0是paste的简化版。

paste0()

r 复制代码
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).

实例

r 复制代码
> 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参数来制定连接符。

注意:在对向量间元素进行连接时使用sep参数,在将向量内全部元素连接时需要使用collapse 参数

实例

cpp 复制代码
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"
相关推荐
Never_Satisfied4 分钟前
在HTML & CSS中,nth-child、nth-of-type详解
前端·css·html
一只大袋鼠6 分钟前
并发编程(三):线程快照统计・grep+awk+sort+uniq 实战详解
java·开发语言·多线程·并发编程
Hx_Ma1622 分钟前
前台模块以及分页逻辑
java·开发语言
亓才孓27 分钟前
AspectJ和SpringAOP的区别
java·开发语言
睡不着的可乐27 分钟前
createElement → VNode 是怎么创建的
前端·javascript·vue.js
光影少年27 分钟前
前端css如何实现水平垂直居中?
前端·javascript·css
大鹏说大话28 分钟前
破局单体瓶颈:SQLParser 解析器的分层架构重构实战
开发语言
tod11331 分钟前
C++ 核心知识点全解析(八)
开发语言·c++·面试经验
Ljwuhe34 分钟前
C++类与对象(上)
开发语言·c++
十启树36 分钟前
QGis开发环境部署
开发语言·gis·qgis