[R] Object oriented programming in R.

David Winsemius dwinsemius at comcast.net
Tue Sep 14 15:55:39 CEST 2010


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 <djmuser at gmail.com>
>
> Cc: Rhelp <r-help at r-project.org>
> 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 <jholtman at gmail.com>
>>
>> Cc: Tal Galili <tal.galili at gmail.com>; Rhelp <r-help at r-project.org>
>> 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 <tal.galili at gmail.com>
>>>
>>> Cc: Rhelp <r-help at r-project.org>
>>> 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



More information about the R-help mailing list