Re: [R] request: To access a particular list

From: jim holtman <jholtman_at_gmail.com>
Date: Fri, 27 Jun 2008 23:21:41 -0400

what does 'str(vr)' show as the structure of the list you are creating?

On Fri, Jun 27, 2008 at 3:19 AM, Muhammad Azam <mazam72_at_yahoo.com> wrote:
> 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)[[1]]; s1=s[1]; s2=s[2]; 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
> [[1]]
> [1] 4
>
> [[1]]
> [1] 4
>
> [[2]]
> [1] 4 4 3
>
> [[1]]
> [1] 4
>
> [[2]]
> [1] 4 4 3
>
> [[3]]
> [1] 4 4 3
>
> [[1]]
> [1] 4
>
> [[2]]
> [1] 4 4 3
>
> [[3]]
> [1] 4 4 3
>
> [[4]]
> [1] 4 4 3
>
> But if i print(vr[[n]]), i get result like an array
> [1] 4
> [1] 4 4 3
> [1] 4 4 3
> [1] 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
>
> Muhammad Azam
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_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.
Received on Sat 28 Jun 2008 - 03:23:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 28 Jun 2008 - 03:31:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive