[R] read.data? without separator

jim holtman jholtman at gmail.com
Mon Dec 27 01:27:29 CET 2010


I have a problem with 'read.data' also in that I don't see that as a
function in the 'base'; I assume you meant read.table.

Also you did not indicate is all the lines were the same length.  Here
is a solution to return a list is each character broken out
separately.

> x <- readLines(textConnection("# comment
+ 1?0001010101
+ 101010??1010"))
> closeAllConnections()
> # split lines 2-n into a list of separate characters
> result <- lapply(x[-1], function(.line) strsplit(.line, '')[[1]])
> result
[[1]]
 [1] "1" "?" "0" "0" "0" "1" "0" "1" "0" "1" "0" "1"

[[2]]
 [1] "1" "0" "1" "0" "1" "0" "?" "?" "1" "0" "1" "0"



On Sun, Dec 26, 2010 at 1:04 PM, Fror <fror at interia.pl> wrote:
>
> Hello,
>
> I have a problem with read.data. For example I have a file
>
> # comment
> 1?0001010101
> 101010??1010
>
> with comment on first line and data layout without separator. How I could
> read data that each character\sign was in another column. It is trivial
> probably, but I have no idea for it.
>
> Thank's,
> Kacper
> --
> View this message in context: http://r.789695.n4.nabble.com/read-data-without-separator-tp3164358p3164358.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list