[R] Decoding raw vectors every other byte
Alex van der Spek
doorz at xs4all.nl
Wed Jun 16 13:15:43 CEST 2010
I have to decode raw vectors read from a connection like this:
+++++++++++++++++++
fl<-file.choose()
fb<-file.info(fl)$size
fc<-file(fl)
open(fc,open='rb')
seek(fc,where=offset)
dat<-readBin(fc,'raw',n=(fb-offset),size=1,signed=FALSE)
close(fc)
++++++++++++++++++
The decoding performs a combination of a simple bitwise operator and a
simple arithmatic operator on every other byte in the raw vector dat.
I can code this using a for loop (incrementing the loop counter by 2 every
pass) but would rather use vectorized operations for reasons of speed. I
can create a function with a for loop and vectorize that function but is
there perhaps an easier way to write this? It is enough if this works on
windows only. No need to worry about endianness.
Thanks in advance.
Alex van der Spek
More information about the R-help
mailing list