Re: [R] problem with function "rep"

From: Marc Schwartz <marc_schwartz_at_comcast.net>
Date: Thu, 12 Jun 2008 10:09:31 -0500

on 06/12/2008 09:48 AM Julien Hunt wrote:
> To whom it may concern,
>
> I am currently writing a program where I need to use function rep.
> The results I get are quite confusing. Given two
> vectors A and B, I want to replicate a[1] b[1]
> times, a[2] b[2] times and so on.
> All the entries of vector B are positive integers.
> My problem comes from the fact that if I sum up
> all the elements of B, I get a certain
> value x(for example 10000). And if i calculate
> the length of the vector obtained after
> replication, I dont always get x(10000) but
> sometimes I get x sometimes I get 9999 instead of 10000.
> Has this problem been reported before? Do you
> need more information on my specific program.
> Thanks for your time and help,
> Best regards,
>
> Julien Hunt

An example would be most helpful, but presuming that you are using something along the lines of:

   rep(a, each = b)

I would check to be sure that:

   length(a) == length(b)

lest you end up with the issue of recycling values.

HTH, Marc Schwartz



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. Received on Thu 12 Jun 2008 - 18:03:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 12 Jun 2008 - 18:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive