Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.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_Loops_Apply - Fatal编程技术网

如何在r循环中运行函数

如何在r循环中运行函数,r,loops,apply,R,Loops,Apply,我有一个数据框和一组基因组坐标。我希望使用nearest.gene()查找这些坐标周围的基因,它一次打印一个结果。我一直在努力在循环中运行函数: apply(gene_lst, 1, function (x) nearest.gene(chr=gene_lst$Chr, pos=gene_lst$Pos)) 1 2 3 4 5 6 7 8 9 10 "ACBD3" "ACBD3

我有一个数据框和一组基因组坐标。我希望使用
nearest.gene()
查找这些坐标周围的基因,它一次打印一个结果。我一直在努力在循环中运行函数:

apply(gene_lst, 1, function (x) nearest.gene(chr=gene_lst$Chr, pos=gene_lst$Pos))
      1       2       3       4       5       6       7       8       9      10 
"ACBD3" "ACBD3" "ACBD3" "ACBD3" "ACBD3" "ACBD3" "ACBD3" "ACBD3" "ACBD3" "ACBD3"
它将覆盖接下来九个坐标的第一个输出。
是否有更好的方法运行此函数?

我想您可以尝试以下代码,您应该将
x
传递到函数
nearest.gene()


在你的
apply
函数中,你没有将
x
传递到你的函数
nearest.gene()
谢谢你指出这一点。它解决了问题吗?希望它能很好地工作……是的,它做到了。再次感谢你的帮助,太好了!如果你认为我的回答有帮助,请随意投票/接受。谢谢:)
apply(gene_lst, 1, function (x) nearest.gene(chr=x["Chr"], pos=x["Pos"]))