paste()
and paste0()
concatenate vectors after converting to a character.paste (..., sep = " ", collapse = NULL)
paste0(..., collapse = NULL)
The parameters are:
- … : objects to be converted to a character vector
-
sep
: string to separate the terms
-
collapse
: optional character string to separate the resultspaste()
:(x = c('A', 'B', 'C'))
## [1] "A" "B" "C"
(y = c('one', 'two', 'three'))
## [1] "one" "two" "three"
paste(x,y, sep = "")
## [1] "Aone" "Btwo" "Cthree"
paste(x,y, sep = " ")
## [1] "A one" "B two" "C three"
paste(x,y, sep = "_")
## [1] "A_one" "B_two" "C_three"
(x = c('A', 'B', 'C'))
## [1] "A" "B" "C"
(y = c('1', '2', '3'))
## [1] "1" "2" "3"
paste(x,y, sep = "", collapse = " -- ")
## [1] "A1 -- B2 -- C3"
paste(x,y, sep = " ", collapse = " -- ")
## [1] "A 1 -- B 2 -- C 3"
paste0
:paste0(..., collapse)
is equivalent to paste(..., sep = "", collapse)
.paste0(x,y)
## [1] "A1" "B2" "C3"
paste(x,y, sep = "")
## [1] "A1" "B2" "C3"
paste0(x,y, collapse = " -- ")
## [1] "A1 -- B2 -- C3"
par(mfrow = c(1,2))
plot(iris$Species, iris$Sepal.Length, names = paste(toupper(levels(iris$Species)), "S.L.", sep = " - "), las = 2, col = 'aquamarine2', cex.axis = 0.60)
plot(iris$Species, iris$Sepal.Width, names = paste(toupper(levels(iris$Species)), "S.W.", sep = " - "), las = 2, col = 'aquamarine4', cex.axis = 0.60)
No comments:
Post a Comment