paste和paste0的区别
2023-03-07 09:03:04 时间
从帮助文档看,paste和paste0只有< sep = " " >这一个参数有区别
paste (..., sep = " ", collapse = NULL, recycle0 = FALSE)
paste0(..., collapse = NULL, recycle0 = FALSE)
- 首先看一下这两个函数都是怎么使用的,使用帮助文档的数据进行解析
- paste函数
paste(month.abb, nth)
[1] "Jan 1st" "Feb 2nd" "Mar 3rd" "Apr 4th" "May 5th" "Jun 6th" "Jul 7th" "Aug 8th" "Sep 9th" "Oct 10th"
[11] "Nov 11th" "Dec 12th"
paste(month.abb, nth, sep = ": ")
[1] "Jan: 1st" "Feb: 2nd" "Mar: 3rd" "Apr: 4th" "May: 5th" "Jun: 6th" "Jul: 7th" "Aug: 8th" "Sep: 9th"
[10] "Oct: 10th" "Nov: 11th" "Dec: 12th"
paste(month.abb, nth,collapse = "; ")
[1] "Jan 1st; Feb 2nd; Mar 3rd; Apr 4th; May 5th; Jun 6th; Jul 7th; Aug 8th; Sep 9th; Oct 10th; Nov 11th; Dec 12th"
paste(month.abb, nth, sep = ": ", collapse = "; ")
[1] "Jan: 1st; Feb: 2nd; Mar: 3rd; Apr: 4th; May: 5th; Jun: 6th; Jul: 7th; Aug: 8th; Sep: 9th; Oct: 10th; Nov: 11th; Dec: 12th"
因而得出结论
paste函数变量之间连接时空格作为默认的分隔符
参数sep = ": "变量之间连接使用 ": " 作为分割符
参数collapse = "; " 当所有的变量坍缩为一个向量时,"; "作为变量连接之后的分隔符
- 以同样的方式验证paste0函数
paste0(month.abb, nth)
[1] "Jan1st" "Feb2nd" "Mar3rd" "Apr4th" "May5th" "Jun6th" "Jul7th" "Aug8th" "Sep9th" "Oct10th" "Nov11th"
[12] "Dec12th"
paste0(month.abb, nth, sep = " ")
[1] "Jan1st " "Feb2nd " "Mar3rd " "Apr4th " "May5th " "Jun6th " "Jul7th " "Aug8th " "Sep9th " "Oct10th "
[11] "Nov11th " "Dec12th "
paste0(month.abb, nth, sep = ": ")
[1] "Jan1st: " "Feb2nd: " "Mar3rd: " "Apr4th: " "May5th: " "Jun6th: " "Jul7th: " "Aug8th: " "Sep9th: "
[10] "Oct10th: " "Nov11th: " "Dec12th: "
paste0(month.abb, nth,collapse = "; ")
[1] "Jan1st; Feb2nd; Mar3rd; Apr4th; May5th; Jun6th; Jul7th; Aug8th; Sep9th; Oct10th; Nov11th; Dec12th"
paste0(month.abb, nth, sep = ": ", collapse = "; ")
[1] "Jan1st: ; Feb2nd: ; Mar3rd: ; Apr4th: ; May5th: ; Jun6th: ; Jul7th: ; Aug8th: ; Sep9th: ; Oct10th: ; Nov11th: ; Dec12th: "
paste0函数变量之间连接时没有分隔符
使用参数sep = " "变量之间也不会出现空格,反而会在变量最后添加分割符
使用参数sep = ": "会在变量最后添加
参数collapse = " " 当所有的变量坍缩为一个向量时," "作为变量连接之后的分隔符
- 因此最后得出结论: sep = " "作为paste函数变量之间连接的分隔符,paste函数变量之间连接无分隔符,如果使用了,只会在变量最后加上分隔符 参数collapse = " " 当所有的变量坍缩为一个向量时," "作为变量连接之后的分隔符,paste函数和paste0函数使用效果相同
相关文章
- 在 Go 里用 CGO?这 7 个问题你要关注!
- 9款优秀的去中心化通讯软件 Matrix 的客户端
- 求职数据分析,项目经验该怎么写
- 在OKR中,我看到了数据驱动业务的未来
- 火山引擎云原生大数据在金融行业的实践
- OpenHarmony富设备移植指南(二)—从postmarketOS获取移植资源
- 《数据成熟度指数》报告:64%的企业领袖认为大多数员工“不懂数据”
- OpenHarmony 小型系统兼容性测试指南
- 肯睿中国(Cloudera):2023年企业数字战略三大趋势预测
- 适用于 Linux 的十大命令行游戏
- GNOME 截图工具的新旧截图方式
- System76 即将推出的 COSMIC 桌面正在酝酿大变化
- 2GB 内存 8GB 存储即可流畅运行,Windows 11 极致精简版系统 Tiny11 发布
- 迎接 ecode:一个即将推出的具有全新图形用户界面框架的现代、轻量级代码编辑器
- loongarch架构介绍(三)—地址翻译
- Go 语言怎么解决编译器错误“err is shadowed during return”?
- 敏捷:可能被开发人员遗忘的部分
- Denodo预测2023年数据管理和分析的未来
- 利用数据推动可持续发展
- 在 Vue3 中实现 React 原生 Hooks(useState、useEffect),深入理解 React Hooks 的