从帮助文档看,paste和paste0只有< sep = " " >这一个参数有区别
paste (..., sep = " ", collapse = NULL, recycle0 = FALSE)
paste0(..., collapse = NULL, recycle0 = FALSE)
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(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 = " " 当所有的变量坍缩为一个向量时," "作为变量连接之后的分隔符
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。