On 25/04/2010 12:52 PM, Matthew Keller wrote:
Hi all,

Probably a rudimentary question. I have a flat file that looks like
this (the real one has ~10e6 elements):

10110100101001011101011

and I want to pull that into R as a vector, but with each digit being
it's own element. There are no separators between the digits. How can
I accomplish this? Thanks in advance!


Is it broken up into lines at all? Then read.fwf might be what you want. If it's just a huge collection of 0s and 1s with no line breaks, then use readChar(filename, nchar=1) to read the individual characters, and later convert them to digits using ifelse(), e.g.

chars <- readChar(filename, nchar=1)
digits <- ifelse(chars=="1", 1, ifelse(chars == "0", 0, NA))

if (any(is.na(digits))) stop("not all 0s and 1s!")

Duncan Murdoch

______________________________________________
R-help@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.

Reply via email to