-3
> B_linkages <- function (J,j) {sum((X-X_omit(J,j))/X[j+56*(J-1)])}
> B_linkages(1,1)
[1] 0.9723767

This one works just fine but

> B_linkages_inter <- function (I,J) {
+   for (j in 1:56) {
+     for (i in 1:56) {
+       sum((X[i+56*(I-1)]-X_omit(J,j)[i+56*(I-1)])/X[j+56*(J-1)])
+     }
+   }
+ }
> 
> B_linkages_inter(1,1)
> 1+2
[1] 3

B_linkages_inter(1,1) does not return any output compared to the previous function.

> 1+2
[1] 3 

is what I did to check if the R has stopped or not. Why isn't "B_linkages_inter(1,1)" showing any results? X is an 2464*2464 matrix, X_omit(J,j) is a function which generates a matrix using the inverse of a 2464*2464 matrix.

user73233
  • 11
  • 4
  • This seems to be a duplicate of the question http://stackoverflow.com/questions/21541012/r-function-with-no-return-value. – 67342343 Mar 26 '17 at 15:46

1 Answers1

2

Your function does a loop but doesn't do anything with the calculations. You have to store the results inside the loop like so:

out <- NULL
for (i in 1:10){
res <- i*2
out <- c(out,res)
}
out
 [1]  2  4  6  8 10 12 14 16 18 20
Pierre Lapointe
  • 16,017
  • 2
  • 43
  • 56