[R] Requesting for help on the problem of "subscript out of bounds"
Rui Barradas
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sat Oct 6 13:28:09 CEST 2018
Hello,
I suggested NROW (all uppercase) because it works even if its argument,
in your case ts, has only one dimension, nrow needs 2-dim objects.
I have now noticed that you are indexing ts as if it has two dimensions,
and that r is created with function matrix() but then you index it with
just one dimension.
r[i] <- approx_entropy(ts[i,], edim = 2, r = 0.2*sd(ts[i,]), elag = 1)
Shouldn't it be ts[i] or r[i, ] ?
Hope this helps,
Rui Barradas
Às 10:34 de 06/10/2018, Subhamitra Patra escreveu:
> I am extremely sorry to say that both the suggestions did not work.
>
> I did not understand the suggestion of Prof. Lemon. So, Sir, Can you
> please clarify me your suggestion?
>
>
> I tried the suggestion of Ruipbarradas. It does not work.
>
>
> Please help me out for which I shall be always grateful to you.
>
> Thanks in advance.
>
> On Sat, Oct 6, 2018 at 2:48 PM ruipbarradas <ruipbarradas using sapo.pt
> <mailto:ruipbarradas using sapo.pt>> wrote:
>
> Hello,
>
> Instead of nrow try all uppercase:
>
> N <- NROW (ts)
>
>
> Hope this helps,
>
> Rui Barradas
>
>
>
>
> Enviado a partir do meu smartphone Samsung Galaxy.
> -------- Mensagem original --------
> De: Subhamitra Patra <subhamitra.patra using gmail.com
> <mailto:subhamitra.patra using gmail.com>>
> Data: 06/10/2018 10:14 (GMT+00:00)
> Para: drjimlemon using gmail.com <mailto:drjimlemon using gmail.com>
> Cc: r-help using r-project.org <mailto:r-help using r-project.org>
> Assunto: Re: [R] Requesting for help on the problem of "subscript
> out of bounds"
>
> Hello Sir,
>
> I tried by defining mat, but still facing the same problem.
>
> Hence, mat represents the time series. This time, I defined it as ts and
> tried, but still having the same problem.
>
> In particular, the problem is coming in the following line
> *for (i in 1:N){*
> *+ r[i]<-approx_entropy(ts[i,], edim = 2, r = 0.2*sd(ts[i,]), elag =
> 1) *
>
> where i is unable to synchronize with the no. of rows i.e. rows and
> thus I
> am getting the error of
>
> *Error in `[<-`(`*tmp*`, i, , value = ts[i:(N - m + i)]) :
> subscript out
> of bounds*
>
> For your reference, I am providing my full code with an explanation as
> follows.
>
> The function
>
> approx_entropy(ts, edim = 2, r = 0.2*sd(ts), elag = 1)
>
> from the package,pracma I am calculating the approximate entropy of time
> series.ts
>
> I have a matrix of time series (one series per row i.e. 51 rows and 1
> column) and I would estimate the approximate entropy for each of
> the rows,
> storing the results in a vector. So, I have written a code
>
> library(pracma)
>
> N<-nrow(ts)
> r<-matrix(0, nrow = N, ncol = 1)for (i in 1:N){
> r[i]<-approx_entropy(ts[i,], edim = 2, r = 0.2*sd(ts[i,]),
> elag = 1)}
>
> * After calculating for 1 series, I need to calculate the same
> things for
> the multiple series by changing the dimension of the ncol.*
>
> Please help me in this regard.
>
> Thanks in advance.
>
> On Sat, Oct 6, 2018 at 2:22 PM Jim Lemon <drjimlemon using gmail.com
> <mailto:drjimlemon using gmail.com>> wrote:
>
> > Hi Subhamitra,
> > Where I think the error arises is in the line:
> >
> > N<-nrow(mat)
> >
> > Since we don't know what "mat" is, we don't know what nrow(mat) will
> > return. If "mat" is not a matrix or data frame, it is likely to be
> > NULL. Try this:
> >
> > print(N)
> >
> > after defining it and see what it is.
> >
> > Jim
> >
> > On Sat, Oct 6, 2018 at 5:51 PM Subhamitra Patra
> > <subhamitra.patra using gmail.com <mailto:subhamitra.patra using gmail.com>>
> wrote:
> > >
> > > Hello friends,
> > >
> > > I am very new in this R world. But, still doing some programming by
> > > learning. While running one code, I found the problem of
> "subscript out
> > of
> > > bounds". Please suggest me how to overcome this problem? For your
> > > reference, I am uploading my code here.
> > >
> > > The function
> > >
> > > approx_entropy(ts, edim =2, r = 0.2*sd(ts), elag = 1)
> > >
> > > library(pracma)
> > >
> > > N<-nrow(mat)
> > > r<-matrix(0, nrow = N, ncol = 1)for (i in 1:N){
> > > r[i]<-approx_entropy(mat[i,], edim = 2, r =
> 0.2*sd(mat[i,]), elag =
> > 1)}
> > >
> > > After running this code, I am getting the error of
> > >
> > > *"subscript out of bounds"*
> > >
> > > Please help me for which I shall be always grateful to you.
> > >
> > > Thanks in advance.
> > >
> > >
> > >
> > > --
> > > *Best Regards,*
> > > *Subhamitra Patra*
> > > *Phd. Research Scholar*
> > > *Department of Humanities and Social Sciences*
> > > *Indian Institute of Technology, Kharagpur*
> > > *INDIA*
> > >
> > > [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > R-help using r-project.org <mailto:R-help using r-project.org> mailing list
> -- To UNSUBSCRIBE and more, see
> > > 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.
> >
>
>
> --
> *Best Regards,*
> *Subhamitra Patra*
> *Phd. Research Scholar*
> *Department of Humanities and Social Sciences*
> *Indian Institute of Technology, Kharagpur*
> *INDIA*
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org <mailto:R-help using r-project.org> mailing list --
> To UNSUBSCRIBE and more, see
> 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.
>
>
>
> --
> *Best Regards,*
> *Subhamitra Patra*
> *Phd. Research Scholar*
> *Department of Humanities and Social Sciences*
> *Indian Institute of Technology, Kharagpur*
> *INDIA*
More information about the R-help
mailing list