Assigning a value to the global variable (and a argument of a function aswell) R
<p>I am currently working on my master thesis (model of a evolutionary trust game). And I have a following problem. I have several types of investors and trustees that are paired to play the trust game. Investors and trustees are defined as vectors. What I would like my code(trust game) to do is that it takes the (globally defined) investor and trustee. They play together the iteration of the trust game and then the globally defined variables are updated inside the function trust game. I would like that it would work for any investor\trustee that is used as the argument of the function trustgame. Do you know how could I code this? I am not sure aswell if it will help you but I post my code aswell.</p>

<pre><code>    #### defining trustees ####
# [1] honor\abuse
# [2] information about previous interaction - relevant to investors who buy the information
# [3] payoff
# [4] number of interactions
trustee1 &lt;- c(1,0,0,0)
#### defining investors ####
# [1] buy\not buy
# [2-4] investment decision if buying information in case 1(TH), case 2(TA), case 3(NT)
# [5] aggregated payoff
# [6] number of interactions in one generation
investor1 &lt;- c(1,1,1,1,0,0)


here is the code for the trust game

trustgame &lt;- function(investor,trustee)
{ investordecision &lt;- NULL
trusteedecision &lt;- trustee[1]
investor[6] &lt;- investor[6]+1
trustee[4] &lt;- trustee[4]+1
if (investor[1]==0) investordecision &lt;- investor[2]
if (investor[1]==1)
{ if (trustee[2]==1) investordecision &lt;- investor[2]
if (trustee[2]==2) investordecision &lt;- investor[3]
if (trustee[2]==3) investordecision &lt;- investor[4]
if (trustee[2]==0) investordecision &lt;- rbinom(1,1,0.5)
}
if (investordecision==1 &amp;&amp; trustee[2]==1) trustee[2] &lt;- 1
if (investordecision==1 &amp;&amp; trustee[2]==0) trustee[2] &lt;- 2  
if (investordecision==0) trustee[2] &lt;- 3

if (investordecision==1 &amp;&amp; trusteedecision==1)
{trustee[3] &lt;- trustee[3] +3
investor[5] &lt;- investor[5] + 3 }
if (investordecision==1 &amp;&amp; trusteedecision==0)
{trustee[3] &lt;- trustee[3] +5
investor[5] &lt;- investor[5] + 0 }
if (investordecision==0 &amp;&amp; trusteedecision==0)
{trustee[3] &lt;- trustee[3] +1
investor[5] &lt;- investor[5] + 1 }
if (investordecision==0 &amp;&amp; trusteedecision==1)
{trustee[3] &lt;- trustee[3] +1
investor[5] &lt;- investor[5] + 1 }

}
</code></pre>