# [R] Just a little problem

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Sat Nov 6 20:44:32 CET 2004

```On 06-Nov-04 lefevre-gallois wrote:
> I begin with R and I couldn't find in the manuels how I can solve this
> this problem
> find n such as |1/ni*sum(Wi)|<0.2
> with Wi<-c(rnorm(200,0,1))
> Thanks for helping
> Best regards

Not sure that I understand the problem.

If ni is a single number (i.e. not involved in the summation)
then

ni <- 5/abs(sum(Wi))

gives an lower bound for ni; if ni is to be an integer then

ni <- floor(5/abs(sum(Wi)))+1

Since there is the (rare) possibility that 5/abs(sum(Wi)) may
be an exact integer, and you want "<" rather than "<=", in that
case you will need (ni + 1) rather than ni. So test the answer:

ni <- 5/abs(sum(Wi))
if(floor(ni) == ni) {ni <- floor(ni)+1} else {ni <- floor)ni)}

However, your use of "ni" and "Wi" suggests that you might be
thinking of "i" as a summation index, with each of {ni} and {Wi}
being a series of numbers, perhaps really meaning

|1/sum(ni*Wi)| < 0.2

in which case the problem would not have a definite solution
unless you state restrictions on the series {ni}.

Hoping this helps,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861  [NB: New number!]
Date: 06-Nov-04                                       Time: 18:51:47
------------------------------ XFMail ------------------------------

```