[R] how to make read in a vector of 0s and 1s with no space between them

Henrik Bengtsson hb at stat.berkeley.edu
Sun Apr 25 20:25:41 CEST 2010


See readBin(), e.g.

r <- readBin(pathname, what="raw", n=10e6);
str(r);
# raw [1:21] 30 31 30 31 ...
c <- rawToChar(x, multiple=TRUE);
str(c);
# chr [1:21] "0" "1" "0" "1" "0" "0" "1" "0" "1" "0" ...
i <- as.integer(r);
str(i);
#  int [1:21] 48 49 48 49 48 48 49 48 49 48 ...

/Henrik

On Sun, Apr 25, 2010 at 6:52 PM, Matthew Keller <mckellercran at gmail.com> 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!
>
> Matt
>
> --
> Matthew C Keller
> Asst. Professor of Psychology
> University of Colorado at Boulder
> www.matthewckeller.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.
>



More information about the R-help mailing list