1

For context, I have a dataset v, and I want to apply 1-exp(-x[i]*theta) to the i'th element of v in succession.

Assume I know the value of theta. I then want to store this as a vector so that I can sort it, and apply it to another function (a 'goodness-of-fit test statistic).

Is there a standard way of doing this?

Matt
  • 7,255
  • 2
  • 12
  • 34
bernoon
  • 13
  • 3
  • Welcome to SO, Bernoon. Please read [how to create a minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) and update your question. – Len Greski Apr 25 '20 at 18:37

1 Answers1

1

R is manipulating vectors so, if v is a vector, you can directly pass your equation as follow:

v2 <- 1 - exp(-v*theta)

And it will be apply to each element of v and stored it in v2 object (which will also be a vector).

here an example:

v <- 1:10
theta  = 5

> 1 - exp(-v*theta)

[1] 0.9932621 0.9999546 0.9999997 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
dc37
  • 15,840
  • 4
  • 15
  • 32
  • As it is it is difficult to help, please edit your question and provide a reproducible example of you matrix as described here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. Also, please provide the code behind `compute`. – dc37 Apr 25 '20 at 19:39