November 15, 2013

String Reverse in R

String reversing is a common operation especially in Bioinformatics. However, this function is not provided in R, not even in the "stringr" package. Here you can find the code:


str_reverse <- function(x){
  return(sapply(lapply(strsplit(x, NULL), rev), paste, collapse=""))
}

s <- "abc"
s1 <- str_reverse(s)
print(s1)

No comments:

Post a Comment