# [R] request: To access a particular list

Date: Fri, 27 Jun 2008 00:19:34 -0700 (PDT)

Dear R community
I have a problem to access particular list. I have a code given below where there is recursive process. It is not possible to run it because there are few other functions involved inside like sv, LN, RN etc.

k=0; n=0; variable=c(); vr<-list()
func <- function(data,testdata)

{
.
.
if(......){

```                  n<<-n+1; vr[[n]] <<- variable; print(vr)
}else
{
k <<- k + 1; data1 = data; data2 = testdata; s=sv(data1)[]; s1=s; s2=s; variable[k] <<- s1
data=LN(data1,s1,s2); testdata=LN(data2,s1,s2)

func(data,testdata);

data=RN(data1,s1,s2); testdata=RN(data2,s1,s2)

func(data,testdata)
}
}
func(m,w)

```

Actually i made an global array to store s1 named "variable". It contains "k" values. When it enters into "if", i made a list of variable named "vr". So it will make "n" lists. If i get the print out of "vr", i will get
[]
 4

[]
 4

[]
 4 4 3

[]
 4

[]
 4 4 3

[]
 4 4 3

[]
 4

[]
 4 4 3

[]
 4 4 3

[]
 4 4 3

But if i print(vr[[n]]), i get result like an array
 4
 4 4 3
 4 4 3
 4 4 3
I want to access a particular list vr[[n-1]], but it gives an error "Error in print(vr[[n - 1]]) : attempt to select less than one element". How can i tackle this problem to access vr[[n-1]]. Please give some suitable suggestions.

Thanks and best regards

```