# Re: [R] request: An array declarion problem

From: jim holtman <jholtman_at_gmail.com>
Date: Wed, 04 Jun 2008 08:14:06 -0400

When I run your code, I get a different error:

> j=10; ss=150; r=array(0 , c( j , ss )); rr=array(0 , c( j , ss ));
r1=array(0 , c( j-1 , ss )); r2=array(0 , c( j-1 , ss ));
> r3=array(0 , c( 2 , ss ))
>
> for(i in 1:j-1){

```+                        r1[ i , ] <- r[ j+1, ]-r[ j, ]; r2[ i , ] <- rr[
j+1, ]-rr[ j, ]
+                        r3[ i,]=rbind(r1[ i, ], r2[ i, ])
+                    }
```

Error: subscript out of bounds
>

This is probably due to 'r' being dimensioned (j,ss) and you are referencing 'r[j+1,]' which is r[11,]. Also I think you want "for(i in 1:(j-1))", notice the difference:

> 1:j-1

[1] 0 1 2 3 4 5 6 7 8 9
> 1:(j-1)
[1] 1 2 3 4 5 6 7 8 9

On Tue, Jun 3, 2008 at 1:58 PM, Muhammad Azam <mazam72_at_yahoo.com> wrote:

> Dear R users
> I tried a lot to solve the following problem but could not. I have two
> arrays having same order i.e 1 by 150.
>
> j=10; ss=150; r=array(0 , c( j , ss )); rr=array(0 , c( j , ss ));
> r1=array(0 , c( j-1 , ss )); r2=array(0 , c( j-1 , ss ));
> r3=array(0 , c( 2 , ss ))
>
> for(i in 1:j-1){
> r1[ i , ] <- r[ j+1, ]-r[ j, ]; r2[ i , ] <- rr[
> j+1, ]-rr[ j, ]
> }
>
> Now i want to "rbind" the results of r1 and r2 for each time. Now the order
> of r3[ j, ] will become 2 by 150. I used the following form in the loop
>
> r3[ i,]=rbind(r1[ i, ], r2[ i, ])
>
> But there is an error message
>
> Error in r3[i, ] = rbind(r1[i, ], r2[i, ]) : number of items to replace is
> not a multiple of replacement length
>
>
> I am looking for some suggestion to solve the problem. Thanks and
>
>
> best regards
>
> Ph.D. Student
> Department of Medical Statistics,
> Informatics and Health Economics
> University of Innsbruck, Austria
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

```--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help