Re: [R] create structs in R.

From: Uwe Ligges <ligges_at_statistik.tu-dortmund.de>
Date: Sat, 14 May 2011 16:26:24 +0200

On 14.05.2011 13:28, Alaios wrote:
> Dear all,
> so far when I want to create a struct with a substructs I create.
> Lists with sublists by using functions and replicate.
>
> This will end up in to a struct that is addressed like that
>
> for (i in c(1:100){
> for (j in c(1:100){
> Mystruct[[1]][[2]][[1]][[i]][[k]]<-dosomething()

You can do it recursively using a vector of indices:

Mystruct[[c(1, 2, 1, i, k)]] <- dosomething()

in order to improve readability.

Uwe Ligges

> }
> }
> It is not hard for one to understand that this form for addressing subfields of the struct [[1]][[2]][[1]]... and so on, make hard to track which field of the strut you are addressing to. Even worse when I open my code after one week I usually take some time to understand which field I wanted to address.
>
>
> Is there something more easier that I can do to face both these types of problem?
>
> I would like to thank you in advance for your help
>
> Best Regards
> Alex
>
> ______________________________________________
> 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.



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 14 May 2011 - 14:28:39 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 14 May 2011 - 14:30:06 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