Skip to content
Back to formatted view

Raw Message

Message-ID: <C78751EC-FB42-4A96-8E8B-69026166B2F0@comcast.net>
Date: 2009-11-03T03:18:20Z
From: David Winsemius
Subject: re ading tokens
In-Reply-To: <26159915.post@talk.nabble.com>

On Nov 2, 2009, at 8:00 PM, j daniel wrote:

>
> Greetings,
>
> I am not familiar with processing text in R.  Can someone tell me  
> how to
> read each line of words as separate elements in a list?
>
> FE, I would like to turn:
>
> word1 word2 word3
> word2 word4
>
> into a list of length two with three character elements in the first  
> list
> and two elements in the second.  I know that this should be easy,  
> but I am a
> little confused by the text functions.

 > txt <- textConnection("word1 word2 word3
+ word2 word4")
 > strsplit(readLines(txt), " ")
[[1]]
[1] "word1" "word2" "word3"

[[2]]
[1] "word2" "word4"
>
-- 

David Winsemius, MD
Heritage Laboratories
West Hartford, CT