Object oriented programming in R.

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Object oriented programming in R.

alaios
Hello everyone.
I would like to create many objects with R. Does R support objects?

The number of objects needed is not predetermined and it is a parameter
specified by the user.
If the user selects to create many objects like 100, would it be possible to
handle each one by some index?

I would like to thank you in advance for your help.


Best Regards
Alex


     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Object oriented programming in R.

Tal Galili
Hello Alaios,
I see a bunch of good materials here:
http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R

<http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R>Did
you look into them ?

----------------Contact
Details:-------------------------------------------------------
Contact me: [hidden email] |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------




On Tue, Sep 14, 2010 at 9:20 AM, Alaios <[hidden email]> wrote:

> Hello everyone.
> I would like to create many objects with R. Does R support objects?
>
> The number of objects needed is not predetermined and it is a parameter
> specified by the user.
> If the user selects to create many objects like 100, would it be possible
> to
> handle each one by some index?
>
> I would like to thank you in advance for your help.
>
>
> Best Regards
> Alex
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Object oriented programming in R.

alaios
Thank you very much. I checked the tutorials that on that list but still I do
not know how to create many objects of the same type. Can you please help me
with that?

Best Regards
Alex




________________________________
From: Tal Galili <[hidden email]>

Cc: Rhelp <[hidden email]>
Sent: Tue, September 14, 2010 10:11:36 AM
Subject: Re: [R] Object oriented programming in R.


Hello Alaios,
I see a bunch of good materials here:
http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R


Did you look into them ?

----------------Contact
Details:-------------------------------------------------------
Contact me: [hidden email] |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------








Hello everyone.

>I would like to create many objects with R. Does R support objects?
>
>The number of objects needed is not predetermined and it is a parameter
>specified by the user.
>If the user selects to create many objects like 100, would it be possible to
>handle each one by some index?
>
>I would like to thank you in advance for your help.
>
>
>Best Regards
>Alex
>
>
>
>       [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] 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.
>



     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Object oriented programming in R.

jholtman
It depends on what you mean by objects.  If you are just looking at
creating many named variables that are going to hold values (e.g.,
reading in data from several files that you want to correlate
separately), then consider the use of 'lists'.  Can you provide a
little more detail on exactly the problem that you are trying to
solve, and then maybe we can propose a solution.

On Tue, Sep 14, 2010 at 5:55 AM, Alaios <[hidden email]> wrote:

> Thank you very much. I checked the tutorials that on that list but still I do
> not know how to create many objects of the same type. Can you please help me
> with that?
>
> Best Regards
> Alex
>
>
>
>
> ________________________________
> From: Tal Galili <[hidden email]>
>
> Cc: Rhelp <[hidden email]>
> Sent: Tue, September 14, 2010 10:11:36 AM
> Subject: Re: [R] Object oriented programming in R.
>
>
> Hello Alaios,
> I see a bunch of good materials here:
> http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R
>
>
> Did you look into them ?
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: [hidden email] |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
> ----------------------------------------------------------------------------------------------
>
>
>
>
>
>
>
>
> Hello everyone.
>>I would like to create many objects with R. Does R support objects?
>>
>>The number of objects needed is not predetermined and it is a parameter
>>specified by the user.
>>If the user selects to create many objects like 100, would it be possible to
>>handle each one by some index?
>>
>>I would like to thank you in advance for your help.
>>
>>
>>Best Regards
>>Alex
>>
>>
>>
>>       [[alternative HTML version deleted]]
>>
>>______________________________________________
>>[hidden email] 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.
>>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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 that you are trying to solve?

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Object oriented programming in R.

Liviu Andronic
In reply to this post by alaios
On Tue, Sep 14, 2010 at 12:55 PM, Alaios <[hidden email]> wrote:
> Thank you very much. I checked the tutorials that on that list but still I do
> not know how to create many objects of the same type. Can you please help me
> with that?
>
Is this what you need?
for(i in 1:100){
        assign(paste('tmp', i, sep=''), NULL)
}
ls()

Liviu

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Object oriented programming in R.

mbedward
In reply to this post by alaios
Hello,

I think you will have to specify your requirements (or at least area
of interest) in much greater detail to get any very meaningful input
from people here. Meanwhile there are countless examples of
object-oriented programming using R on the web complete with code.

Michael


On 14 September 2010 19:55, Alaios <[hidden email]> wrote:
>
> Thank you very much. I checked the tutorials that on that list but still I do
> not know how to create many objects of the same type. Can you please help me
> with that?
>
> Best Regards
> Alex
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Object oriented programming in R.

Rainer M Krug-6
In reply to this post by Liviu Andronic
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 14/09/10 13:51, Liviu Andronic wrote:

> On Tue, Sep 14, 2010 at 12:55 PM, Alaios <[hidden email]> wrote:
>> Thank you very much. I checked the tutorials that on that list but still I do
>> not know how to create many objects of the same type. Can you please help me
>> with that?
>>
> Is this what you need?
> for(i in 1:100){
> assign(paste('tmp', i, sep=''), NULL)
> }
> ls()
>
> Liviu
>
> ______________________________________________
> [hidden email] 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.

look at ?rep:

x <- rep(list(createTheObject(), 10)

x will be a list containing 10 times the object created by createTheObject()

Cheers,

Rainer

- --
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:        +33 - (0)9 53 10 27 44
Cell:       +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:      [hidden email]

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyPY0kACgkQoYgNqgF2egr5hQCePJ+20z2d64SPVOtIFxv7dmBs
ASwAnAhQbm4snJFqYj1dOn2w6NSRLIC+
=wuQC
-----END PGP SIGNATURE-----

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Object oriented programming in R.

alaios
In reply to this post by jholtman
Here are some more information:
I would like to create some agents that span over a specific area map.Every
agent needs to have its own data structures like one or two matrices and one
list.

I think that the best way to do this is to create objects and every instance of
an object will be used for a single agent.

The number of agents is not predetermined and it varies for any execution.
So I read this value from the command line interface and then I would like to
initiate so many objects as the agents. I think that the best way to do that is
to create using a for loop a list containing as many objects as the agents are.

I would like to thank you in advance for your help

Best Regards
Alex



________________________________
From: jim holtman <[hidden email]>

Cc: Tal Galili <[hidden email]>; Rhelp <[hidden email]>
Sent: Tue, September 14, 2010 1:40:37 PM
Subject: Re: [R] Object oriented programming in R.

It depends on what you mean by objects.  If you are just looking at
creating many named variables that are going to hold values (e.g.,
reading in data from several files that you want to correlate
separately), then consider the use of 'lists'.  Can you provide a
little more detail on exactly the problem that you are trying to
solve, and then maybe we can propose a solution.


> Thank you very much. I checked the tutorials that on that list but still I do
> not know how to create many objects of the same type. Can you please help me
> with that?
>
> Best Regards
> Alex
>
>
>
>
> ________________________________
> From: Tal Galili <[hidden email]>
>
> Cc: Rhelp <[hidden email]>
> Sent: Tue, September 14, 2010 10:11:36 AM
> Subject: Re: [R] Object oriented programming in R.
>
>
> Hello Alaios,
> I see a bunch of good materials here:
>http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R
>R
>
>
> Did you look into them ?
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: [hidden email] |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
>----------------------------------------------------------------------------------------------
>-
>
>
>
>
>
>
>
>
> Hello everyone.
>>I would like to create many objects with R. Does R support objects?
>>
>>The number of objects needed is not predetermined and it is a parameter
>>specified by the user.
>>If the user selects to create many objects like 100, would it be possible to
>>handle each one by some index?
>>
>>I would like to thank you in advance for your help.
>>
>>
>>Best Regards
>>Alex
>>
>>
>>
>>       [[alternative HTML version deleted]]
>>
>>______________________________________________
>>[hidden email] 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.
>>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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 that you are trying to solve?



     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Object oriented programming in R.

djmuseR
Hi:

You could create a list of lists, where the outer list would be between
agents and the inner list within agents. The inner list could have the
'matrices and one list' as separate components for each agent. Of course,
you would have to be able to keep all of this straight :)

HTH,
Dennis

On Tue, Sep 14, 2010 at 5:00 AM, Alaios <[hidden email]> wrote:

> Here are some more information:
> I would like to create some agents that span over a specific area map.Every
> agent needs to have its own data structures like one or two matrices and
> one
> list.
>
> I think that the best way to do this is to create objects and every
> instance of
> an object will be used for a single agent.
>
> The number of agents is not predetermined and it varies for any execution.
> So I read this value from the command line interface and then I would like
> to
> initiate so many objects as the agents. I think that the best way to do
> that is
> to create using a for loop a list containing as many objects as the agents
> are.
>
> I would like to thank you in advance for your help
>
> Best Regards
> Alex
>
>
>
> ________________________________
> From: jim holtman <[hidden email]>
>
> Cc: Tal Galili <[hidden email]>; Rhelp <[hidden email]>
> Sent: Tue, September 14, 2010 1:40:37 PM
> Subject: Re: [R] Object oriented programming in R.
>
> It depends on what you mean by objects.  If you are just looking at
> creating many named variables that are going to hold values (e.g.,
> reading in data from several files that you want to correlate
> separately), then consider the use of 'lists'.  Can you provide a
> little more detail on exactly the problem that you are trying to
> solve, and then maybe we can propose a solution.
>
>
> > Thank you very much. I checked the tutorials that on that list but still
> I do
> > not know how to create many objects of the same type. Can you please help
> me
> > with that?
> >
> > Best Regards
> > Alex
> >
> >
> >
> >
> > ________________________________
> > From: Tal Galili <[hidden email]>
> >
> > Cc: Rhelp <[hidden email]>
> > Sent: Tue, September 14, 2010 10:11:36 AM
> > Subject: Re: [R] Object oriented programming in R.
> >
> >
> > Hello Alaios,
> > I see a bunch of good materials here:
> >
> http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R
> >R
> >
> >
> > Did you look into them ?
> >
> > ----------------Contact
> > Details:-------------------------------------------------------
> > Contact me: [hidden email] |  972-52-7275845
> > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> > www.r-statistics.com (English)
>
> >----------------------------------------------------------------------------------------------
> >-
> >
> >
> >
> >
> >
> >
> >
> >
> > Hello everyone.
> >>I would like to create many objects with R. Does R support objects?
> >>
> >>The number of objects needed is not predetermined and it is a parameter
> >>specified by the user.
> >>If the user selects to create many objects like 100, would it be possible
> to
> >>handle each one by some index?
> >>
> >>I would like to thank you in advance for your help.
> >>
> >>
> >>Best Regards
> >>Alex
> >>
> >>
> >>
> >>       [[alternative HTML version deleted]]
> >>
> >>______________________________________________
> >>[hidden email] 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.
> >>
> >
> >
> >
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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 that you are trying to solve?
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Object oriented programming in R.

alaios
I would like to thank you very much all that you helped me so far.
So I tried to check how the following works

fred <- list(happy = 1:10, name = "squash")
rep(fred, 5)

This returns the following :

> fred[1]
$happy
 [1]  1  2  3  4  5  6  7  8  9 10


> fred[2]
$name
[1] "squash"

What I am trying to do is to address the number 5 of the fred[1] $happy value.
I tried something like fred[1][5] fred[1,5]
but it didn't work

I would like to thank you in advance for your help

Best Regards
Alex




________________________________
From: Dennis Murphy <[hidden email]>

Cc: Rhelp <[hidden email]>
Sent: Tue, September 14, 2010 3:13:37 PM
Subject: Re: [R] Object oriented programming in R.

Hi:

You could create a list of lists, where the outer list would be between agents
and the inner list within agents. The inner list could have the 'matrices and
one list' as separate components for each agent. Of course, you would have to be
able to keep all of this straight :)

HTH,
Dennis




Here are some more information:

>I would like to create some agents that span over a specific area map.Every
>agent needs to have its own data structures like one or two matrices and one
>list.
>
>I think that the best way to do this is to create objects and every instance of
>an object will be used for a single agent.
>
>The number of agents is not predetermined and it varies for any execution.
>So I read this value from the command line interface and then I would like to
>initiate so many objects as the agents. I think that the best way to do that is
>to create using a for loop a list containing as many objects as the agents are.
>
>
>I would like to thank you in advance for your help
>
>Best Regards
>Alex
>
>
>
>________________________________
>From: jim holtman <[hidden email]>
>
>Cc: Tal Galili <[hidden email]>; Rhelp <[hidden email]>
>Sent: Tue, September 14, 2010 1:40:37 PM
>
>Subject: Re: [R] Object oriented programming in R.
>
>
>It depends on what you mean by objects.  If you are just looking at
>creating many named variables that are going to hold values (e.g.,
>reading in data from several files that you want to correlate
>separately), then consider the use of 'lists'.  Can you provide a
>little more detail on exactly the problem that you are trying to
>solve, and then maybe we can propose a solution.
>
>
>
>> Thank you very much. I checked the tutorials that on that list but still I do
>> not know how to create many objects of the same type. Can you please help me
>> with that?
>>
>> Best Regards
>> Alex
>>
>>
>>
>>
>> ________________________________
>> From: Tal Galili <[hidden email]>
>>
>> Cc: Rhelp <[hidden email]>
>> Sent: Tue, September 14, 2010 10:11:36 AM
>> Subject: Re: [R] Object oriented programming in R.
>>
>>
>> Hello Alaios,
>> I see a bunch of good materials here:
>>http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R
>>
>>R
>>
>>
>> Did you look into them ?
>>
>> ----------------Contact
>> Details:-------------------------------------------------------
>> Contact me: [hidden email] |  972-52-7275845
>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
>> www.r-statistics.com (English)
>>----------------------------------------------------------------------------------------------
>>
>>-
>>
>>
>>
>>
>>
>>
>>
>>
>> Hello everyone.
>>>I would like to create many objects with R. Does R support objects?
>>>
>>>The number of objects needed is not predetermined and it is a parameter
>>>specified by the user.
>>>If the user selects to create many objects like 100, would it be possible to
>>>handle each one by some index?
>>>
>>>I would like to thank you in advance for your help.
>>>
>>>
>>>Best Regards
>>>Alex
>>>
>>>
>>>
>>>       [[alternative HTML version deleted]]
>>>
>>>______________________________________________
>>>[hidden email] 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.
>>>
>>
>>
>>
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] 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 that you are trying to solve?
>
>
>
>
>       [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] 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.
>



     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Object oriented programming in R.

jholtman
I think this is what you want.  Notice the use of 'list' in the rep to
create a list of list:

> fred <- list(happy = 1:10, name = "squash")
> x <- rep(list(fred), 5)
> str(x)
List of 5
 $ :List of 2
  ..$ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
  ..$ name : chr "squash"
 $ :List of 2
  ..$ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
  ..$ name : chr "squash"
 $ :List of 2
  ..$ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
  ..$ name : chr "squash"
 $ :List of 2
  ..$ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
  ..$ name : chr "squash"
 $ :List of 2
  ..$ happy: int [1:10] 1 2 3 4 5 6 7 8 9 10
  ..$ name : chr "squash"
> x[[1]]$happy[5]
[1] 5
>


On Tue, Sep 14, 2010 at 9:29 AM, Alaios <[hidden email]> wrote:

> I would like to thank you very much all that you helped me so far.
> So I tried to check how the following works
>
> fred <- list(happy = 1:10, name = "squash")
> rep(fred, 5)
>
> This returns the following :
>
>> fred[1]
> $happy
>  [1]  1  2  3  4  5  6  7  8  9 10
>
>
>> fred[2]
> $name
> [1] "squash"
>
> What I am trying to do is to address the number 5 of the fred[1] $happy value.
> I tried something like fred[1][5] fred[1,5]
> but it didn't work
>
> I would like to thank you in advance for your help
>
> Best Regards
> Alex
>
>
>
>
> ________________________________
> From: Dennis Murphy <[hidden email]>
>
> Cc: Rhelp <[hidden email]>
> Sent: Tue, September 14, 2010 3:13:37 PM
> Subject: Re: [R] Object oriented programming in R.
>
> Hi:
>
> You could create a list of lists, where the outer list would be between agents
> and the inner list within agents. The inner list could have the 'matrices and
> one list' as separate components for each agent. Of course, you would have to be
> able to keep all of this straight :)
>
> HTH,
> Dennis
>
>
>
>
> Here are some more information:
>>I would like to create some agents that span over a specific area map.Every
>>agent needs to have its own data structures like one or two matrices and one
>>list.
>>
>>I think that the best way to do this is to create objects and every instance of
>>an object will be used for a single agent.
>>
>>The number of agents is not predetermined and it varies for any execution.
>>So I read this value from the command line interface and then I would like to
>>initiate so many objects as the agents. I think that the best way to do that is
>>to create using a for loop a list containing as many objects as the agents are.
>>
>>
>>I would like to thank you in advance for your help
>>
>>Best Regards
>>Alex
>>
>>
>>
>>________________________________
>>From: jim holtman <[hidden email]>
>>
>>Cc: Tal Galili <[hidden email]>; Rhelp <[hidden email]>
>>Sent: Tue, September 14, 2010 1:40:37 PM
>>
>>Subject: Re: [R] Object oriented programming in R.
>>
>>
>>It depends on what you mean by objects.  If you are just looking at
>>creating many named variables that are going to hold values (e.g.,
>>reading in data from several files that you want to correlate
>>separately), then consider the use of 'lists'.  Can you provide a
>>little more detail on exactly the problem that you are trying to
>>solve, and then maybe we can propose a solution.
>>
>>
>>
>>> Thank you very much. I checked the tutorials that on that list but still I do
>>> not know how to create many objects of the same type. Can you please help me
>>> with that?
>>>
>>> Best Regards
>>> Alex
>>>
>>>
>>>
>>>
>>> ________________________________
>>> From: Tal Galili <[hidden email]>
>>>
>>> Cc: Rhelp <[hidden email]>
>>> Sent: Tue, September 14, 2010 10:11:36 AM
>>> Subject: Re: [R] Object oriented programming in R.
>>>
>>>
>>> Hello Alaios,
>>> I see a bunch of good materials here:
>>>http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R
>>>
>>>R
>>>
>>>
>>> Did you look into them ?
>>>
>>> ----------------Contact
>>> Details:-------------------------------------------------------
>>> Contact me: [hidden email] |  972-52-7275845
>>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
>>> www.r-statistics.com (English)
>>>----------------------------------------------------------------------------------------------
>>>
>>>-
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Hello everyone.
>>>>I would like to create many objects with R. Does R support objects?
>>>>
>>>>The number of objects needed is not predetermined and it is a parameter
>>>>specified by the user.
>>>>If the user selects to create many objects like 100, would it be possible to
>>>>handle each one by some index?
>>>>
>>>>I would like to thank you in advance for your help.
>>>>
>>>>
>>>>Best Regards
>>>>Alex
>>>>
>>>>
>>>>
>>>>       [[alternative HTML version deleted]]
>>>>
>>>>______________________________________________
>>>>[hidden email] 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.
>>>>
>>>
>>>
>>>
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] 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 that you are trying to solve?
>>
>>
>>
>>
>>       [[alternative HTML version deleted]]
>>
>>______________________________________________
>>[hidden email] 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.
>>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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 that you are trying to solve?

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Object oriented programming in R.

David Winsemius
In reply to this post by alaios

On Sep 14, 2010, at 9:29 AM, Alaios wrote:

> I would like to thank you very much all that you helped me so far.
> So I tried to check how the following works
>
> fred <- list(happy = 1:10, name = "squash")
> rep(fred, 5)
>
> This returns the following :
>
>> fred[1]
> $happy
> [1]  1  2  3  4  5  6  7  8  9 10
>
>
>> fred[2]
> $name
> [1] "squash"

Not on my machine:

 > fred <- list(happy = 1:10, name = "squash")
 > rep(fred, 5)
$happy
  [1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"

$happy
  [1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"

$happy
  [1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"

$happy
  [1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"

$happy
  [1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"


>
> What I am trying to do is to address the number 5 of the fred[1]  
> $happy value.
> I tried something like fred[1][5] fred[1,5]
> but it didn't work

Almost:

 > fred[[1]][5]
[1] 5


>
> I would like to thank you in advance for your help
>
> Best Regards
> Alex
>
> ________________________________
> From: Dennis Murphy <[hidden email]>
>
> Cc: Rhelp <[hidden email]>
> Sent: Tue, September 14, 2010 3:13:37 PM
> Subject: Re: [R] Object oriented programming in R.
>
> Hi:
>
> You could create a list of lists, where the outer list would be  
> between agents
> and the inner list within agents. The inner list could have the  
> 'matrices and
> one list' as separate components for each agent. Of course, you  
> would have to be
> able to keep all of this straight :)
>
> HTH,
> Dennis
>
>
> Here are some more information:
>> I would like to create some agents that span over a specific area  
>> map.Every
>> agent needs to have its own data structures like one or two  
>> matrices and one
>> list.
>>
>> I think that the best way to do this is to create objects and every  
>> instance of
>> an object will be used for a single agent.
>>
>> The number of agents is not predetermined and it varies for any  
>> execution.
>> So I read this value from the command line interface and then I  
>> would like to
>> initiate so many objects as the agents. I think that the best way  
>> to do that is
>> to create using a for loop a list containing as many objects as the  
>> agents are.
>>
>>
>> I would like to thank you in advance for your help
>>
>> Best Regards
>> Alex
>>
>> ________________________________
>> From: jim holtman <[hidden email]>
>>
>> Cc: Tal Galili <[hidden email]>; Rhelp <[hidden email]>
>> Sent: Tue, September 14, 2010 1:40:37 PM
>>
>> Subject: Re: [R] Object oriented programming in R.
>>
>>
>> It depends on what you mean by objects.  If you are just looking at
>> creating many named variables that are going to hold values (e.g.,
>> reading in data from several files that you want to correlate
>> separately), then consider the use of 'lists'.  Can you provide a
>> little more detail on exactly the problem that you are trying to
>> solve, and then maybe we can propose a solution.
>>
>>
>>
>>> Thank you very much. I checked the tutorials that on that list but  
>>> still I do
>>> not know how to create many objects of the same type. Can you  
>>> please help me
>>> with that?
>>>
>>> Best Regards
>>> Alex
>>>
>>>
>>>
>>>
>>> ________________________________
>>> From: Tal Galili <[hidden email]>
>>>
>>> Cc: Rhelp <[hidden email]>
>>> Sent: Tue, September 14, 2010 10:11:36 AM
>>> Subject: Re: [R] Object oriented programming in R.
>>>
>>>
>>> Hello Alaios,
>>> I see a bunch of good materials here:
>>> http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R
>>>
>>> R
>>>
>>>
>>> Did you look into them ?
>>>
>>> ----------------Contact

>>>
>>>
>>>
>>> Hello everyone.
>>>> I would like to create many objects with R. Does R support objects?
>>>>
>>>> The number of objects needed is not predetermined and it is a  
>>>> parameter
>>>> specified by the user.
>>>> If the user selects to create many objects like 100, would it be  
>>>> possible to
>>>> handle each one by some index?
>>>>
>>>> I would like to thank you in advance for your help.
>>>>
>>>>
>>>> Best Regards
>>>> Alex


David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Object oriented programming in R.

yvonnick noel
In reply to this post by alaios
I think you should have a look at the 'proto' package on CRAN.

Yvonnick Noel
University of Brittany, Rennes
France

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Indexing sublists inside lists.

alaios
In reply to this post by David Winsemius
I would like to thank you very much for your reply.
Actually I would like to ask you if there is
a small list called fred:
fred <- list(happy = 1:10, name = "squash")
and a big list called bigfred that included fred list 5 times
bigfred <- rep(fred,5)

Is it possible somehow to index all these sublists(fred) inside bigfred with a
more direct way like
bigfred[1] shows the first sublist fred
bigfred[2][2] shows the second sublist fred, the second element of the fred list

So far I found some way to do this by refering to the sublists by the following:
bigfred[1+index*length(fred)]
where index shows the beginning of a sublist.

I would like to thank you in advance for your help
Best Regards
Alex





________________________________
From: David Winsemius <[hidden email]>

Cc: Dennis Murphy <[hidden email]>; Rhelp <[hidden email]>
Sent: Tue, September 14, 2010 3:55:39 PM
Subject: Re: [R] Object oriented programming in R.


On Sep 14, 2010, at 9:29 AM, Alaios wrote:

> I would like to thank you very much all that you helped me so far.
> So I tried to check how the following works
>
> fred <- list(happy = 1:10, name = "squash")
> rep(fred, 5)
>
> This returns the following :
>
>> fred[1]
> $happy
> [1]  1  2  3  4  5  6  7  8  9 10
>
>
>> fred[2]
> $name
> [1] "squash"

Not on my machine:

> fred <- list(happy = 1:10, name = "squash")
> rep(fred, 5)
$happy
[1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"

$happy
[1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"

$happy
[1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"

$happy
[1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"

$happy
[1]  1  2  3  4  5  6  7  8  9 10

$name
[1] "squash"


>
> What I am trying to do is to address the number 5 of the fred[1] $happy value.
> I tried something like fred[1][5] fred[1,5]
> but it didn't work

Almost:

> fred[[1]][5]
[1] 5


>
> I would like to thank you in advance for your help
>
> Best Regards
> Alex
>
> ________________________________
> From: Dennis Murphy <[hidden email]>
>
> Cc: Rhelp <[hidden email]>
> Sent: Tue, September 14, 2010 3:13:37 PM
> Subject: Re: [R] Object oriented programming in R.
>
> Hi:
>
> You could create a list of lists, where the outer list would be between agents
> and the inner list within agents. The inner list could have the 'matrices and
> one list' as separate components for each agent. Of course, you would have to
>be
> able to keep all of this straight :)
>
> HTH,
> Dennis
>
>
> Here are some more information:
>> I would like to create some agents that span over a specific area map.Every
>> agent needs to have its own data structures like one or two matrices and one
>> list.
>>
>> I think that the best way to do this is to create objects and every instance
>of
>> an object will be used for a single agent.
>>
>> The number of agents is not predetermined and it varies for any execution.
>> So I read this value from the command line interface and then I would like to
>> initiate so many objects as the agents. I think that the best way to do that
>is
>> to create using a for loop a list containing as many objects as the agents
>are.
>>
>>
>> I would like to thank you in advance for your help
>>
>> Best Regards
>> Alex
>>
>> ________________________________
>> From: jim holtman <[hidden email]>
>>
>> Cc: Tal Galili <[hidden email]>; Rhelp <[hidden email]>
>> Sent: Tue, September 14, 2010 1:40:37 PM
>>
>> Subject: Re: [R] Object oriented programming in R.
>>
>>
>> It depends on what you mean by objects.  If you are just looking at
>> creating many named variables that are going to hold values (e.g.,
>> reading in data from several files that you want to correlate
>> separately), then consider the use of 'lists'.  Can you provide a
>> little more detail on exactly the problem that you are trying to
>> solve, and then maybe we can propose a solution.
>>
>>
>>
>>> Thank you very much. I checked the tutorials that on that list but still I
do

>>> not know how to create many objects of the same type. Can you please help me
>>> with that?
>>>
>>> Best Regards
>>> Alex
>>>
>>>
>>>
>>>
>>> ________________________________
>>> From: Tal Galili <[hidden email]>
>>>
>>> Cc: Rhelp <[hidden email]>
>>> Sent: Tue, September 14, 2010 10:11:36 AM
>>> Subject: Re: [R] Object oriented programming in R.
>>>
>>>
>>> Hello Alaios,
>>> I see a bunch of good materials here:
>>>http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R
>>>R
>>>
>>> R
>>>
>>>
>>> Did you look into them ?
>>>
>>> ----------------Contact

>>>
>>>
>>>
>>> Hello everyone.
>>>> I would like to create many objects with R. Does R support objects?
>>>>
>>>> The number of objects needed is not predetermined and it is a parameter
>>>> specified by the user.
>>>> If the user selects to create many objects like 100, would it be possible
to
>>>> handle each one by some index?
>>>>
>>>> I would like to thank you in advance for your help.
>>>>
>>>>
>>>> Best Regards
>>>> Alex


David Winsemius, MD
West Hartford, CT


     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Indexing sublists inside lists.

djmuseR
Hi:

Is this what you were looking for?

frd <- rep('fred', 5)
bigfred <- lapply(frd, get)

On Tue, Sep 21, 2010 at 5:04 AM, Alaios <[hidden email]> wrote:

> I would like to thank you very much for your reply.
> Actually I would like to ask you if there is
> a small list called fred:
> fred <- list(happy = 1:10, name = "squash")
> and a big list called bigfred that included fred list 5 times
> bigfred <- rep(fred,5)
>
> Is it possible somehow to index all these sublists(fred) inside bigfred
> with a more direct way like
> bigfred[1] shows the first sublist fred
> bigfred[2][2] shows the second sublist fred, the second element of the fred
> list
>

Not quite.

bigfred[[1]]   shows the first sublist;
bigfred[[2]][2]    shows the second component of the second sublist (name);
bigfred[[3]][[1]][2] shows the second element of the first component of the
third sublist.

Of course, one can always refer to sublists by name, when defined, as in

bigfred[[2]]$name
bigfred[[3]]$happy[3:5]

HTH,
Dennis

>
> So far I found some way to do this by refering to the sublists by the
> following:
> bigfred[1+index*length(fred)]
> where index shows the beginning of a sublist.
>
> I would like to thank you in advance for your help
> Best Regards
> Alex
>
>
> ------------------------------
> *From:* David Winsemius <[hidden email]>
> *To:* Alaios <[hidden email]>
> *Cc:* Dennis Murphy <[hidden email]>; Rhelp <[hidden email]>
> *Sent:* Tue, September 14, 2010 3:55:39 PM
> *Subject:* Re: [R] Object oriented programming in R.
>
>
> On Sep 14, 2010, at 9:29 AM, Alaios wrote:
>
> > I would like to thank you very much all that you helped me so far.
> > So I tried to check how the following works
> >
> > fred <- list(happy = 1:10, name = "squash")
> > rep(fred, 5)
> >
> > This returns the following :
> >
> >> fred[1]
> > $happy
> > [1]  1  2  3  4  5  6  7  8  9 10
> >
> >
> >> fred[2]
> > $name
> > [1] "squash"
>
> Not on my machine:
>
> > fred <- list(happy = 1:10, name = "squash")
> > rep(fred, 5)
> $happy
> [1]  1  2  3  4  5  6  7  8  9 10
>
> $name
> [1] "squash"
>
> $happy
> [1]  1  2  3  4  5  6  7  8  9 10
>
> $name
> [1] "squash"
>
> $happy
> [1]  1  2  3  4  5  6  7  8  9 10
>
> $name
> [1] "squash"
>
> $happy
> [1]  1  2  3  4  5  6  7  8  9 10
>
> $name
> [1] "squash"
>
> $happy
> [1]  1  2  3  4  5  6  7  8  9 10
>
> $name
> [1] "squash"
>
>
> >
> > What I am trying to do is to address the number 5 of the fred[1] $happy
> value.
> > I tried something like fred[1][5] fred[1,5]
> > but it didn't work
>
> Almost:
>
> > fred[[1]][5]
> [1] 5
>
>
> >
> > I would like to thank you in advance for your help
> >
> > Best Regards
> > Alex
> >
> > ________________________________
> > From: Dennis Murphy <[hidden email]>
> >
> > Cc: Rhelp <[hidden email]>
> > Sent: Tue, September 14, 2010 3:13:37 PM
> > Subject: Re: [R] Object oriented programming in R.
> >
> > Hi:
> >
> > You could create a list of lists, where the outer list would be between
> agents
> > and the inner list within agents. The inner list could have the 'matrices
> and
> > one list' as separate components for each agent. Of course, you would
> have to be
> > able to keep all of this straight :)
> >
> > HTH,
> > Dennis
> >
> >
> > Here are some more information:
> >> I would like to create some agents that span over a specific area
> map.Every
> >> agent needs to have its own data structures like one or two matrices and
> one
> >> list.
> >>
> >> I think that the best way to do this is to create objects and every
> instance of
> >> an object will be used for a single agent.
> >>
> >> The number of agents is not predetermined and it varies for any
> execution.
> >> So I read this value from the command line interface and then I would
> like to
> >> initiate so many objects as the agents. I think that the best way to do
> that is
> >> to create using a for loop a list containing as many objects as the
> agents are.
> >>
> >>
> >> I would like to thank you in advance for your help
> >>
> >> Best Regards
> >> Alex
> >>
> >> ________________________________
> >> From: jim holtman <[hidden email]>
> >>
> >> Cc: Tal Galili <[hidden email]>; Rhelp <[hidden email]>
> >> Sent: Tue, September 14, 2010 1:40:37 PM
> >>
> >> Subject: Re: [R] Object oriented programming in R.
> >>
> >>
> >> It depends on what you mean by objects.  If you are just looking at
> >> creating many named variables that are going to hold values (e.g.,
> >> reading in data from several files that you want to correlate
> >> separately), then consider the use of 'lists'.  Can you provide a
> >> little more detail on exactly the problem that you are trying to
> >> solve, and then maybe we can propose a solution.
> >>
> >>
> >>
> >>> Thank you very much. I checked the tutorials that on that list but
> still I do
> >>> not know how to create many objects of the same type. Can you please
> help me
> >>> with that?
> >>>
> >>> Best Regards
> >>> Alex
> >>>
> >>>
> >>>
> >>>
> >>> ________________________________
> >>> From: Tal Galili <[hidden email]>
> >>>
> >>> Cc: Rhelp <[hidden email]>
> >>> Sent: Tue, September 14, 2010 10:11:36 AM
> >>> Subject: Re: [R] Object oriented programming in R.
> >>>
> >>>
> >>> Hello Alaios,
> >>> I see a bunch of good materials here:
> >>>
> http://www.google.co.il/search?sourceid=chrome&ie=UTF-8&q=Object+oriented+programming+in+R
> >>>
> >>> R
> >>>
> >>>
> >>> Did you look into them ?
> >>>
> >>> ----------------Contact
>
> >>>
> >>>
> >>>
> >>> Hello everyone.
> >>>> I would like to create many objects with R. Does R support objects?
> >>>>
> >>>> The number of objects needed is not predetermined and it is a
> parameter
> >>>> specified by the user.
> >>>> If the user selects to create many objects like 100, would it be
> possible to
> >>>> handle each one by some index?
> >>>>
> >>>> I would like to thank you in advance for your help.
> >>>>
> >>>>
> >>>> Best Regards
> >>>> Alex
>
>
> David Winsemius, MD
> West Hartford, CT
>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.