René Schou
René Schou

Reputation: 103

Double sum computation in R

I'm having problem writing the following double sum into a function in r: s

where the I function is an indicator function and we have n observations x_1...x_n.

I tried something like this

sum( (x <= t) / (sum((x<=x)))^2)

Upvotes: 0

Views: 191

Answers (1)

jogo
jogo

Reputation: 12559

You can do:

sumiI <- function(xi, x) sum(xi<=x)
sum(1/sapply(x[x<=t], FUN=sumI, x=x))

Upvotes: 1

Related Questions