Repeating a user-defined function using replicate() or sapply()

前端 未结 4 1770
太阳男子
太阳男子 2021-02-01 09:52

I have defined a custom function, like this:

my.fun = function() {

      for (i in 1:1000) {
      ...
        for (j in 1:20) {
          ...
        }
      }         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-01 10:41

    Try this:

    final <- replicate(5, my.fun(), simplify = "matrix")
    

    You will get the result of 'final' in the form of matrix.

提交回复
热议问题