[R] using a list to index elements of a list

Pj253 pj253 at cam.ac.uk
Tue Mar 23 16:36:42 CET 2010

Thanks for your reply Ben!

I don't think I want v to be identical to x... I guess I haven't put the
question in the right context. What I'm actually trying to do is... (*
indicates extra information, not necessarily relevant for my question, but
to help put it in context)

A, some  matrix (*a traceless, symmetric matrix of 0's, 1's (representing a

for (i in x[[1]]){
	if (A[1,i]==1) {
	    for (j in x[[2]]){
		    if (A[i,j]==1){

So, here I have used i and j to range over the elements of x[[1]], x[[2]]
(*This prints all the paths of length 2 starting at vertex 1. But I'm trying
to generalise this for a path of length nrow(A), i.e. a Hamiltonian path)*)
I want to iterate this process a certain number of times, so instead of i,j
I thought to use a list of scalars, v.
I don't want v to be identical to x... I want v to be a list of scalars
which range (inside a for loop) over an elements of the list x. (so instead
of for (i in x[[k]]) I have for (v[[k]] in x[[k]])).

I can see how they look similar, but I do think they're different objects.
Hope this is clear. If you still think using 'x' itself would work, can you
explain how so?
View this message in context: http://n4.nabble.com/using-a-list-to-index-elements-of-a-list-tp1679184p1679253.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list