Skip to content

Reading word by word in a dataset

2 messages · John, Andy Bunn

#
Hello All,

I'd like to read first words in lines into a new file.
If I have a data file the following, how can I get the
first words: apple, banana, strawberry?

i1-apple        10$   New_York
i2-banana       5$    London
i3-strawberry   7$    Japan

Is there any similar question already posted to the
list? I am a bit new to R, having a few months of
experience now.

Cheers,

John
#
Something like this should work:

foo <- read.table("text2read.txt", colClasses=c("character", "NULL",
"NULL"))$V1
foo <- gsub("i[0-9]-", "", foo)

HTH, Andy