Skip to content
Prev 170158 / 398506 Next

What is going on?

Lists. You're missing the "list" concept. I'm sure others can explain it
better, but here's the basic idea.

Take a look at l after you do the split:
[[1]]
[1] "1" "2"
[1] 1

strsplit() returns a list of length 1, with two elements, the two
split "bits" of your initial string. The help for strsplit() even says:

   A list of length 'length(x)' the 'i'-th element of which contains
     the vector of splits of 'x[i]'.

You can get the individual components that you expected with
l[[1]][1]
and
l[[1]][2]

This is confusing in the single case, but allows strsplit to work on multiple
strings:
[[1]]
[1] "1" "2"

[[2]]
[1] "3" "4"
[1] "1"
[1] "3"
[1] 2
On Wed, Feb 11, 2009 at 2:18 PM, Paul Johnston <pcj127 at gmail.com> wrote: