Last active
September 7, 2015 15:50
-
-
Save neetsdkasu/a6111aab7a8dda7ae8e3 to your computer and use it in GitHub Desktop.
Concatenate Strings in R ( strConcat function ) [ R言語での文字列の連結 ]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
strConcat <- function(x, sep="") { | |
return(paste(x, collapse=sep)) | |
} | |
# example 1 | |
s <- strConcat(c("abc", "efg", "hij")) | |
cat(s) # output is "abcefghij" | |
# example 2 | |
s <- strConcat(c("abc", "efg", "hij"), sep=",") | |
cat(s) # output is "abc,efg,hij" | |
# example 3 | |
s <- strConcat(c("abc", "efg", "hij"), ",") | |
cat(s) # output is "abc,efg,hij" | |
# example 4 | |
a <- "xyz" | |
b <- "123" | |
u <- strConcat(c(a, b)) | |
cat(u) # output is "xyz123" | |
# example 5 | |
e <- c("a", "b", "c", "d", "e", "f") | |
t <- strConcat(e[2:4]) | |
cat(t) # output is "bcd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment