> 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]
Neden fun2() çalışmıyor? Fun2() ve fun1() aslında aynı şey değil mi?Dış() ve kullanıcı tanımlı işlevlerin kullanımıyla ilgili basit soru?
Details:
‘X’ and ‘Y’ must be suitable arguments for ‘FUN’. Each will be
extended by ‘rep’ to length the products of the lengths of ‘X’ and
‘Y’ before ‘FUN’ is called.
‘FUN’ is called with these two extended vectors as arguments.
Therefore, it must be a vectorized function (or the name of one),
expecting at least two arguments.
ne yaptığını, sen sonra bu vektörün birinci ve ikinci elemanları toplamı, bir vektörü içine iki vektör bitiştirmek vardır düşünün: ?outer
okursanız
Hayır, aynı değiller. fun1 x ve y vektörlerinin toplamını döndürürken, fun2 birleşik x ve y'nin birinci ve ikinci öğelerinin skaler toplamını döndürür. – Andrie