阅读背景:

关于使用outer()和用户定义函数的简单问题?

来源:互联网 
> fun1 <- function(x,y){x+y}
> outer(seq(1,5,length=5),seq(6,10,length=5),fun1)
     [,1] [,2] [,3] [,4] [,5]
[1,]    7    8    9   10   11
[2,]    8    9   10   11   12
[3,]    9   10   11   12   13
[4,]   10   11   12   13   14
[5,]   11   12   13   14   15
> fun2 <- function(x,y){z<-c(x,y);z[1]+z[2]}
> outer(seq(1,5,length=5),seq(6,10,length=5),fun2)
Error in dim(robj) <- c(dX, dY) : 
  dims [product 25] do not match the length of object [1]
> fun1 <- function(x,y){x+y}
> outer(seq(1,5,le



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: