[R] Extracting a range of elements from a vector

2007-08-25 Thread Otis Laws
Dear R users

I am R newbie creating a function that implements the poker test to test 
pseudo random bit generators.
Iam reading the bits from a text file (1 bit per line),  which causes 
each bit to be stored in an element of a numeric vector.

What Iam trying to do is to extract a block of bits of arbitray size 
from the original vector into a smaller numeric vector and then count 
this binary number
 (and keep repeating this until the end of the vector, so that I get a 
vector containing the number of times each binary number has occured) e.g.

original vector:
0, 1,1,0,0,1,0,1,1

using a block size of 3 bits the first smaller vector becomes:
0, 1, 1

At the momemt I do this by iterating through the original vector and set 
the ith element of the smaller vector.
I have looked at using the subset() function but it seems to operate on 
a vector's content rather than index.

This causes the following two main questions:
1. Is there a way to specify a range of vector elements? 
2. Is this the most efficient method, since this could be extremly time 
consuming when used to test millions of bits?


Thanks very much in advance

Otis Laws

__
R-help@stat.math.ethz.ch 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.


Re: [R] Extracting a range of elements from a vector

2007-08-25 Thread Gabor Grothendieck
See ?embed

On 8/25/07, Otis Laws [EMAIL PROTECTED] wrote:
 Dear R users

 I am R newbie creating a function that implements the poker test to test
 pseudo random bit generators.
 Iam reading the bits from a text file (1 bit per line),  which causes
 each bit to be stored in an element of a numeric vector.

 What Iam trying to do is to extract a block of bits of arbitray size
 from the original vector into a smaller numeric vector and then count
 this binary number
  (and keep repeating this until the end of the vector, so that I get a
 vector containing the number of times each binary number has occured) e.g.

 original vector:
 0, 1,1,0,0,1,0,1,1

 using a block size of 3 bits the first smaller vector becomes:
 0, 1, 1

 At the momemt I do this by iterating through the original vector and set
 the ith element of the smaller vector.
 I have looked at using the subset() function but it seems to operate on
 a vector's content rather than index.

 This causes the following two main questions:
 1. Is there a way to specify a range of vector elements?
 2. Is this the most efficient method, since this could be extremly time
 consuming when used to test millions of bits?


 Thanks very much in advance

 Otis Laws

 __
 R-help@stat.math.ethz.ch 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.


__
R-help@stat.math.ethz.ch 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.