Hi everyone,

I'm a complete beginner with R and am trying to use it for my maths project, however I'm getting stuck with what I reckon are some quite elementary things, just because I've never used it before and am teaching myself.

This is what I have so far and what I am doing:

This is a vector which represents a population - it's set to zero at the moment but this is what I will vary eventually.

This is my function:

What I want to do, is create a vector

so that I can form the following:

And for the life of me I can't work out how; I've tried things like this:

And I can see why they don't work, because π(1), π(2), .... , π(100) isn't a sequence like 1:100...

I guess I want the set {π(i) s.t. i is in [1,100]} and then to turn that into a vector?

Is there a better way of defining my function so I can do that?

If anyone can help me out with how to do this, that would be amazing! At the moment I'm resorting to entering all 100 entries manually but this is really inelegant and also annoying because you have to redefine every time popr changes - which it will do!

Thanks so much for your help

Lucy

I'm a complete beginner with R and am trying to use it for my maths project, however I'm getting stuck with what I reckon are some quite elementary things, just because I've never used it before and am teaching myself.

This is what I have so far and what I am doing:

Code:

```
popr = vector(mode='numeric', 100)
> popr
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[69] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
```

This is my function:

Code:

```
π <- function(S)
+ {x <- sum(popr[0:S])
+ return((100-S)*x)}
```

Code:

`Y = (π(1), π(2), .... , π(100))`

Code:

`av.payoffd <- popd%*%Y`

Code:

```
> Y[0:100] = π(1):π(100)
> Y[0:100] = (π(1:100))
```

I guess I want the set {π(i) s.t. i is in [1,100]} and then to turn that into a vector?

Is there a better way of defining my function so I can do that?

If anyone can help me out with how to do this, that would be amazing! At the moment I'm resorting to entering all 100 entries manually but this is really inelegant and also annoying because you have to redefine every time popr changes - which it will do!

Thanks so much for your help

Lucy

Last edited: