Re: [R] summation involving multiple summations

2016-03-23 Thread Greg Snow
You can create a list of functions then use subscripting. E.g.: funvec <- c(sin, cos, tan) for(i in 1:3) { print(funvec[[i]](pi/6)) } Just create the list with the different functions that you want to call, then subscript that list with your n_r variable. You can also look at ?switch, but I t

[R] summation involving multiple summations

2016-03-19 Thread Mahmoud via R-help
Dear R Experts I've a function which involves multiple summations, and the number of summations depends on a random variable named (n-r), where n is known but r is random and rn_r=3 >fx=function(x)sum(sapply(1:n_r, function(j1) {sum(sapply(1:(j1), >function(j2){sum(sapply(1:(j2), >function(j