On 06/26/2010 02:07 PM, Duncan Murdoch wrote:
Jim Hargreaves wrote:
Hi Duncan, list,

Thanks for the advice, but unfortunately that wasn't what was causing my problem. I'm still getting the "Recursive indexing failed at level 2" message even after replacing my unlist(pulse[i]) with pulse[[i]].

Read the second part of my first message, which explains the error. You had two errors in the original expression, and have only fixed one.
Doh!

Working as intended now, thanks very much for your help!

Regards,
Jim Hargreaves

Duncan Murdoch
Error:

> pulse_subset[[1:as.numeric(length(pulse[[i]][as.numeric(peak_start[i]):as.numeric(peak_end[i])]))]] <- pulse[[i]][as.numeric(peak_start[i]):as.numeric(peak_end[i])] Error in pulse_subset[[1:as.numeric(length(pulse[[i]][as.numeric(peak_start[i]):as.numeric(peak_end[i])]))]] <- pulse[[i]][as.numeric(peak_start[i]):as.numeric(peak_end[i])] :
   recursive indexing failed at level 2

It's almost as if the length of pulse[[i]] is too small, but it's length is 1001 and peak_start[i] and peak_end[i] are 192 and 208 respectively.

Also why would the problem crop up only after 200,000 runs?

Bizarre!

Regards,
Jim Hargreaves



On 06/26/2010 01:38 PM, Duncan Murdoch wrote:
On 26/06/2010 8:29 AM, Jim Hargreaves wrote:
On 06/26/2010 01:20 PM, Duncan Murdoch wrote:
On 26/06/2010 7:53 AM, Jim Hargreaves wrote:
Dear fellow R users,

I am replacing elements of a list like so:

pulse_subset[[1:20]]=unlist(pulse[i])[1:20]
If pulse is a list, then pulse[i] is also a list, with one element. I think you want pulse[[i]], which extracts element i.
Ahh, I specified pulse[i] has >20 values in my original mail.
But that could not be correct. Take a look at length(pulse[i]). Assuming that i is a scalar value, length(pulse[i]) will be 1. You really do want pulse[[i]]. You used unlist(pulse[i]) which is sometimes the same as pulse[[i]], but it really depends on what pulse[[i]] is. unlist() is a very crude tool, and you should avoid it unless you really need it.


Basically pulse is a list 1000 elements long, with each element in pulse having between 1000 and 2000 elements of it's own. Pulse is a list of lists. Also as far as I am aware, [[ ]]'s should only be used when assigning values to elements of a list/vector.
Whoever told you that was mistaken.

Duncan Murdoch
unlist(pulse[1]) gives x1, x2, x3, x4, x5 etc. etc.
If pulse_subset is a list, then pulse_subset[[1:20]] is equivalent to pulse_subset[[1]][[2]][[3]][[4]] ... [[20]], i.e. the syntax implies that it is a list containing a list etc, nested 20 levels deep. The error message is telling you that it's not. I'm not sure what your intention is in this case.
Duncan Murdoch
where pulse is a list of lists, and pulse [i] has >20 values.

This gives the error "Recursive Indexing failed at level 2". But, interestingly this instruction is part of a loop which has gone through about 200,000 iterations before giving this error.

Actual code:
pulse_subset[[1:(length(unlist(pulse[i])[as.numeric(peak_start[i]):as.numeric(peak_end[i])]))]] <- unlist(pulse[i])[as.numeric(peak_start[i]):as.numeric(peak_end[i])]

Error in pulse_subset[[1:(length(unlist(pulse[i])[as.numeric(peak_start[i]):as.numeric(peak_end[i])]))]] <- unlist(pulse[i])[as.numeric(peak_start[i]):as.numeric(peak_end[i])] :
   recursive indexing failed at level 2

If anyone could shed some light I'd be rather grateful.

Regards,
Jim Hargreaves

______________________________________________
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.
______________________________________________
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.

______________________________________________
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.


______________________________________________
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.

Reply via email to