htu.98
htu.98

Reputation: 1

Implementing equations in R

I am new to R (also not too good at math) and I am trying to calculate this equation in R with some difficulties:

The formula I am trying to calculate

X is some integer data I have, with 550 samples.

Any help is appreciated since I am unsure how to do this. I think I have to use a for loop and the sum() function but other than that I don;t know.

Upvotes: 0

Views: 39

Answers (1)

Captain Hat
Captain Hat

Reputation: 3257

R supports vectorisation, which means you very rarely need to implement for loops.

For example, you can solve your equation like so:

## I'm just making up a long numerical vector for x - obviously you can use anything
x <- 1:1000
solution <- sum(20/x)^0.5

Unless the brackets denote the integral, rather than the sum? In which case:

solution <- sum( (20/x)^0.5 )

Upvotes: 2

Related Questions