Re: [R] Help with understanding [[]] [] array, list, matrix referencing

From: David Barron <mothsailor_at_googlemail.com>
Date: Tue 24 Oct 2006 - 11:09:40 GMT

Have you tried help("["), which gives a good explanation.

On 24/10/06, Joe W. Byers <Joe-Byers@utulsa.edu> wrote:
> Hi all,
>
> I would greatly appreciate some help understanding how R references
> arrays, matrices, lists, and objects using [[]] and []. I have read the
> R guides and several tutorials but I am not the fastest kid on the block
> so I am still having difficulty understanding this. For examples the
> following code produces a 5 element list of 2X5 random numbers that I
> then convert to a 2X5X5 matrix.
> cov<-matrix(c(.4,-.1,-.1,.3),nrow=2,ncol=2)
> rnds<-NULL;
> for (i in 1:5){
> t1<-rnorm(5,cov)
> t2<-rnorm(5,cov)
> t3<-rbind(t1,t2)
> rnds[i]<-list(t3)
> }
>
> rnds.matrix<-array(unlist(rnds),dim=c(2,5,5));
>
> To access the matrix rnds.matrix I use rnds.matrix[x,y,z]. This I
> understand.
>
> To access the list I user [[z]][x,y]. This I do not understand. I
> found by chance this reference notation in an old mailing list that
> helped me.
>
> I could use some help in knowing when to use [[]] referencing and when
> to use [] referencing. If there is a really good book, webpage, or link
> with explanation and examples I would appreciate you forwarding the the
> citation.
>
> Thank you
> Joe
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>

-- 
=================================
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

______________________________________________
R-help@stat.math.ethz.ch 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 Tue Oct 24 21:21:23 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 24 Oct 2006 - 12:30:13 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.