0

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.

Captain Hat
  • 2,444
  • 1
  • 14
  • 31
htu.98
  • 1
  • 1

1 Answers1

2

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 )
Captain Hat
  • 2,444
  • 1
  • 14
  • 31