[R] reverse string

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jul 14 12:54:01 CEST 2010


On Wed, Jul 14, 2010 at 6:13 AM, Trafim Vanishek <rdapamoga at gmail.com> wrote:
> Dear all,
>
> Are there any functions in R to reverse the order of the string.
> smth like reverse("abc") to get "cba"?
>

Suppose data.frame DF has a column for which we wish to reverse each
component. Then using the builtin month.abb try this:

> DF <- data.frame(month = month.abb)
> library(sqldf)
> sqldf("select reverse(month) from DF")
   reverse(month)
1             naJ
2             beF
3             raM
4             rpA
5             yaM
6             nuJ
7             luJ
8             guA
9             peS
10            tcO
11            voN
12            ceD



More information about the R-help mailing list