Skip to content
Prev 350004 / 398506 Next

scan - open text file as list

Hello,

I try to open a text file test.txt with the content

* a b d
* z u i h hh
* h bh kk

so that I get a list with each line as a vector with the letters as
elements of the the vector.

My approach ...
test <- scan ("test.txt", what="character", sep="\n")
Read 3 items
<- a[-1]})
[[1]]
[1] "a" "b" "d"

[[2]]
[1] "z"  "u"  "i"  "h"  "hh"

[[3]]
[1] "h"  "bh" "kk"

... the result is okay but I dont think it is an elegant solution. One
comment: I dont know how many lines my "real" test.txt will have.
Thanks Hermann