## parsing command arguments for (arg in commandArgs(TRUE)) { eval(parse(text=arg)) } ## check if a given integer is prime isPrime = function(n) { if (n <= 3) { return (TRUE) } if (any((n %% 2:floor(sqrt(n))) == 0)) { return (FALSE) } return (TRUE) } ## estimate mean only using observation with prime indices estMeanPrimes = function (x) { n = length(x) ind = sapply(1:n, isPrime) return (mean(x[ind])) } # simulate data x = rnorm(n) # estimate mean estMeanPrimes(x)