Skip to content

Last char of a string in a list -> list of strings

3 messages · Gabor Grothendieck, Fredrik Karlsson

#
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
but that gives me something like:

...
[[2136]]
[1] "H" "L"

[[2137]]
[1] "H"

[[2138]]
[1] "H" "L"

[[2139]]
[1] "L"

So, what am I doing wrong?

/Fredrik
#
Try this:
+ "%L", "H*L", "!H*L", "L%", "%L", "%L", "%L", "%L", "H*L", "!H*L",
+ "L%", "H*", "%L", "H*L", "L_%", "%L", "%H", "%H", "!H*L", "%H",
+ "H*", "%H", "%H", "H%", "H*", "!H*L", "H*L", "!H*L", "H*", "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%", "%L", "H*L",
+ "!H*L", "L%", "%L", "H*L", "%L", "H*L", "%H", "H*L", "%L")
[1] "L" "L" "L" "L" "L" "L" "L" "L" "L" "L" "L" "L" "L" "L" "L" "L"
"L" "L" "L" "L" "H" "L" "L" "L" "L" "H" "H" "L" "H" "H" "H" "H" "H"
"H" "L" "L" "L" "H"
[39] "L" "L" "L" "L" "L" "H" "H" "H" "H" "H" "H" "L" "H" "L" "L" "H"
"L" "L" "L" "L" "L" "L" "L" "L" "L" "L" "L" "H" "L" "L"
On Wed, Mar 18, 2009 at 11:10 AM, Fredrik Karlsson <dargosch at gmail.com> wrote:
#
Dear Gabor,

Thank you very much for this very helpful suggestion. Indeed, I was
making it too complicated by spliting the string into a vector.

Thank you!

/Fredrik

On Wed, Mar 18, 2009 at 3:37 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote: