paste() 和 paste0() 的区别 [英] Difference between paste() and paste0()
问题描述
R 的新手,谁能解释一下 paste()
和 paste0()
之间的区别,我从一些帖子中了解到
Being new to R, can someone please explain the difference between paste()
and paste0()
, what I had understood from some post is that
paste0("a", "b") === paste("a", "b", sep="")
我也尝试过这样的事情
a <- c("a","b","c")
b <- c("y","w","q")
paste(a,b,sep = "_")
**output**
"a_y" "b_w" "c_q"
使用 paste0()
a <- c("a","b","c")
b <- c("y","w","q")
paste0(a,b,sep = "_")
**output**
"ay_" "bw_" "cq_"
难道只是paste()
在元素之间使用分隔符而paste0()
在元素之后使用分隔符?
Is it just that paste()
uses separator between elements and paste0()
uses separator after the elements?
推荐答案
paste
有 3 个参数.
paste (..., sep = " ", collapse = NULL)
...
是你的东西想要粘贴在一起,sep 和崩溃是得到它的人完毕.我粘贴了三个基本的东西:
paste (..., sep = " ", collapse = NULL)
The ...
is the stuff you
want to paste together and sep and collapse are the guys to get it
done. There are three basic things I paste together:
- 一堆单独的字符串.
- 为元素粘贴了 2 个或更多字符串.
- 一根绳子混在一起.
这里有一个例子,虽然没有正确的参数
Here's an example of each, though not with the correct arguments
paste("A", 1, "%")
#一堆单独的字符串.
paste("A", 1, "%")
#A bunch of individual character strings.
paste(1:4, letters[1:4])
#2 个或更多字符串粘贴元素元素.
paste(1:4, letters[1:4])
#2 or more strings pasted element for
element.
paste(1:10)
#一个字符串混在一起.这是每个的 sep/collapse 规则:
paste(1:10)
#One string smushed together. Here's the
sep/collapse rule for each:
- 一堆单独的字符串——你想要 sep
- 2 个或更多字符串为元素粘贴元素.– 你想要 sep
- 一根绳子混在一起.- Smushin 需要折叠
paste0
的缩写:paste(x, sep="")
所以它让我们更懒并且更有效率.
paste0
is short for: paste(x, sep="")
So it allows us to be lazier
and more efficient.
paste0("a", "b") == paste("a", "b", sep="") ## [1] TRUE
这篇关于paste() 和 paste0() 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!