[R] for loop error
ecoinfo
ecoinformatics at gmail.com
Fri Dec 23 13:22:54 CET 2005
I guess you missed {} after for ():
for (j in 1:groups) # no.groups=50
## ?? for (j in 1:groups) {
for (k in 1:length(ratio))
## ?? for () {
On 12/23/05, Ita.Cirovic-Donev at hypo-alpe-adria.com
<Ita.Cirovic-Donev at hypo-alpe-adria.com> wrote:
>
>
>
>
> I have the following code and I am not sure what's wrong or how to make it
> work.
>
> B <- matrix(1,nrow=50,ncol=2)
> for (i in 1:length(size.out)){ # length(size.out=2) these
> are the two variables
> X <- var.range[i,1] # min
> Y <- var.range[i,1] # min
> ratio <- size.out[,i]
> for (j in 1:groups) # no.groups=50
> A <- 0
> X <- Y # min
> Y <- X + span.group.size[i,1] # min + (max-min)/50
> for (k in 1:length(ratio)) # there are
> 11065 observations per variable
> if ((X <= ratio[k]) & (ratio[k] >= Y))
> A <- A+1
> B[j,i] <- A
> print(B)
> }
>
> basically, what I want to do is obtain a range for the variables in
> size.out data frame. I do this by computing min and max and getting a span.
> Then I have
>
> var.range is defined by row=variables from size.out and col=[min max]
> span.group.size is defined as row=variables from size.out and col=[span]
>
> Now I want to count how many values fall into defined range with if ((X <=
> ratio[k]) & (ratio[k] >= Y)). This count I need to store which I then later
> on plot.
>
> Thanks.
> ____________________
> Ita Cirovic-Donev
>
> ______________________________________________
> R-help at 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
>
--
Xiaohua Dai, Dr.
More information about the R-help
mailing list