[R] Extracting the first element of a list

Ross Darnell r.darnell at shrs.uq.edu.au
Wed Mar 27 01:00:46 CET 2002


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list