Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 数据帧的函数_R_Function - Fatal编程技术网

R 数据帧的函数

R 数据帧的函数,r,function,R,Function,我试图为数据帧构建一个函数,但运行它时出错 问题:我应该如何将函数“应用”到数据帧,使其工作?原子向量问题有解决办法吗? 错误是: x$country:$运算符中的错误对于原子向量无效 功能是: occ_fction <- function (x) { x <- subset(x, x$country== "DE") nace <- model.matrix(~ nace_code -1, data=x) x <- cbind(x, nace)

我试图为数据帧构建一个函数,但运行它时出错

问题:我应该如何将函数“应用”到数据帧,使其工作?原子向量问题有解决办法吗?

错误是:

x$country:$运算符中的错误对于原子向量无效

功能是:

occ_fction <- function (x)
{
    x <- subset(x, x$country== "DE")
    nace <- model.matrix(~ nace_code -1, data=x)
    x <- cbind(x, nace)
    rm(nace)
    # some more stuff here
}

occ\u fction(mydata)
有什么问题?您在这里使用
mapply
的理由是什么?您能让数据重现吗<代码>数据输出(occ功能)谢谢!这项工作:occ功能(mydata)!!!如果你把它变成一个答案,我会接受它:@Andrey Kolyadin
mapply(occ_fction, mydata)