Skip to content

Instantly share code, notes, and snippets.

@neetsdkasu
Last active September 7, 2015 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neetsdkasu/a6111aab7a8dda7ae8e3 to your computer and use it in GitHub Desktop.
Save neetsdkasu/a6111aab7a8dda7ae8e3 to your computer and use it in GitHub Desktop.
Concatenate Strings in R ( strConcat function ) [ R言語での文字列の連結 ]
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