[R] Last char of a string in a list -> list of strings

Fredrik Karlsson dargosch at gmail.com
Wed Mar 18 16:10:07 CET 2009

Dear list,

This seems like a very simple problem, but I am failing to loose a
dimension (I think).
I have list, like this:

[2072] "!H*L" "L%"   "%L"   "H*L"  "L%"   "%L"   "H*L"  "H*L"  "L%"
"%L"   "H*L"  "!H*L" "L%"   "%L"   "%L"   "%L"   "%L"   "H*L"  "!H*L"
[2091] "L%"   "H*"   "%L"   "H*L"  "L_%"  "%L"   "%H"   "%H"   "!H*L"
"%H"   "H*"   "%H"   "%H"   "H%"   "H*"   "!H*L" "H*L"  "!H*L" "H*"
[2110] "H*L"  "L_%"  "%L"   "%L"   "H*L"  "L*H"  "H%"   "%H"   "L*H"
"H%"   "%H"   "H*L"  "%H"   "%L"   "H*L"  "%H"   "%L"   "H*L"  "L%"
[2129] "%L"   "H*L"  "!H*L" "L%"   "%L"   "H*L"  "%L"   "H*L"  "%H"
"H*L"  "%L"

What I would like to do is

1) Remove all the %!*0 characters
2) Get the last character of what remains for each string
3) Get a list, comparable to the one above, but with only one
character (so, the last three data points would become list(H,L,L)

I tried

> strsplit(gsub("[*_!%0]*","",TADescSub$ExtendedLabel,""),"")

but that gives me something like:

[1] "H" "L"

[1] "H"

[1] "H" "L"

[1] "L"

So, what am I doing wrong?


"Life is like a trumpet - if you don't put anything into it, you don't
get anything out of it."

More information about the R-help mailing list