Function/loops 问题

Function/loops issue

作为我工作的一部分,我正在编写一段相当复杂的代码。很长一段时间以来一直很痛苦,我开始犯无用的错误。所以我试图将我的问题简化为一段非常基本的代码,但仍然犯了错误。谁能解释错误是什么以及如何解决?谢谢!

(数据框'my files'在底部)

library(plyr)
setwd("J:/R/Loops")

funct <- function(x,v) 
  (x^2) + (v^2)

myfiles <- read.csv("myfiles.csv", header=TRUE)
funct(myfiles)

Error in funct(myfiles) : argument "v" is missing, with no default

lapply(myfiles, funct)

Error in FUN(X[[i]], ...) : argument "v" is missing, with no default

数据

myfiles <- read.table(header = TRUE, text = "x  v
1  7
2  8
3  9
4 10
5 11
6 12")

您可以使用 ?mapply

mapply(funct,myfiles$x, myfiles$v)
[1]  50  68  90 116 146 180