使用函数包括数据帧引用的外部函数错误
我试图使用外部函数获取3D表面。并且我定义的函数在data.frame中引用列。以下是可重现的简要代码。使用函数包括数据帧引用的外部函数错误
的test.txt是
a b c 1 0 0
2 0 0
3 0 0
6 0 0
4 0 0
和代码显示为错误
test<- read.table(file="test.txt",header=TRUE) testf<-function(q,w){
test$b<-q
test$c<-w
sum(test$b)+sum(test$c)
}
x<-seq(1,10,by = 1)
y<-seq(0,30,by = 1)
z<-outer(x,y,testf)
结果是
Error in `$<-.data.frame`(`*tmp*`, "b", value = c(1, 2, 3, 4, 5, 6, 7, : replacement has 310 rows, data has 5
5.stop(sprintf(ngettext(N, "replacement has %d row, data has %d",
"replacement has %d rows, data has %d"), N, nrows), domain = NA)
4.`$<-.data.frame`(`*tmp*`, "b", value = c(1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, ...
3.`$<-`(`*tmp*`, "b", value = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...
2. FUN(X, Y, ...)
1. outer(x, y, testf)
功能本身似乎因为testf(1,1)的作品没有问题
> testf(1,1) [1] 10
任何意见将不胜感激!
回答:
我觉得for loop
只产生Z轴值
以上是 使用函数包括数据帧引用的外部函数错误 的全部内容, 来源链接: utcz.com/qa/259790.html