Skip to content
Back to formatted view

Raw Message

Message-ID: <m0g02mdglt.fsf@localhost.localdomain>
Date: 2002-03-27T00:00:46Z
From: Ross Darnell
Subject: Extracting the first element of a list
In-Reply-To: <F212EAHoxvbQaPCgGwe0001a971@hotmail.com>

Perhaps some kind person might show me the way to extract the first element of a list.

The example is

tmp <- c("A", "B C","BC D")

I want the first "word" from each of these elements, i.e. "A" ,"B" ,"BC" 

strsplit(tmp," ") returns

[[1]]
[1] "A"

[[2]]
[1] "B" "C"

[[3]]
[1] "BC" "D"

I have had no success in trying to extract the first element.

Of course there may be another way to get the same result.


Thanks
Ross Darnell

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._