m<-matrix(byrow=FALSE) t<-as.list(na.exclude(x)) j<-0 o<-0 for(i in 1:998) { d<- 5*(i-1)+3 if(t[[d]][[1]]>80) { j<-j+1 e[j]<-d l<-length(t[[d]]) u<-t[[d]] price_rand<-t[[d-1]] n<-0 for(k in 1:l) { if((u[k]>49)&&(u[k]<51)) { n<-n+1 m[n,j]<-price_rand[k] } } } } I am getting error in assigning the values to a matrix. *Error in m[n, j] <- price_rand[k] : subscript out of bounds* * * How to correct this ? Please suggest me the correct method. Thanx for the help in the advance -- Avinash Barnwal Final year undergraduate student Statistics and informatics Department of Mathematics IIT Kharagpur [[alternative HTML version deleted]]
Take a look at "m". Your error should be quite clear More generally: we don't do homework help on this list. Michael Weylandt On Sat, Sep 10, 2011 at 12:59 PM, avinash barnwal < avinashbarnwal123@gmail.com> wrote:> m<-matrix(byrow=FALSE) > t<-as.list(na.exclude(x)) > j<-0 > o<-0 > for(i in 1:998) > { > d<- 5*(i-1)+3 > if(t[[d]][[1]]>80) > { > j<-j+1 > e[j]<-d > l<-length(t[[d]]) > u<-t[[d]] > price_rand<-t[[d-1]] > n<-0 > for(k in 1:l) > { > > > > > > > if((u[k]>49)&&(u[k]<51)) > { > n<-n+1 > m[n,j]<-price_rand[k] > } > } > } > } > > I am getting error in assigning the values to a matrix. > *Error in m[n, j] <- price_rand[k] : subscript out of bounds* > * > * > How to correct this ? > Please suggest me the correct method. > > Thanx for the help in the advance > -- > Avinash Barnwal > Final year undergraduate student > Statistics and informatics > Department of Mathematics > IIT Kharagpur > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
?debug ?browser Read up on debugging your script. On Saturday, September 10, 2011, avinash barnwal < avinashbarnwal123@gmail.com> wrote:> m<-matrix(byrow=FALSE) > t<-as.list(na.exclude(x))_ > j<-0 > o<-0 > for(i in 1:998) > { > d<- 5*(i-1)+3 > if(t[[d]][[1]]>80) > { > j<-j+1 > e[j]<-d > l<-length(t[[d]]) > u<-t[[d]] > price_rand<-t[[d-1]] > n<-0 > for(k in 1:l) > { > > > > > > > if((u[k]>49)&&(u[k]<51)) > { > n<-n+1 > m[n,j]<-price_rand[k] > } > } > } > } > > I am getting error in assigning the values to a matrix. > *Error in m[n, j] <- price_rand[k] : subscript out of bounds* > * > * > How to correct this ? > Please suggest me the correct method. > > Thanx for the help in the advance > -- > Avinash Barnwal > Final year undergraduate student > Statistics and informatics > Department of Mathematics > IIT Kharagpur > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? [[alternative HTML version deleted]]