0
我总是碰到想要使用函数的参数到apply
函数的问题。我环顾四周,但我无法找到合适的答案...如何在函数参数中包含函数参数?
例如
我有一个像
dput (tab)
> structure(c(108.13, 108.13, 107.7, 107.66, 107.65, NA, NA, 115.56,
115.5, 115.45, NA, NA, NA, 122.72, 122.66, 124.81, 124.82, 124.87,
124.91, 124.94, NA, NA, NA, NA, 130.18), .Dim = c(5L, 5L), .Dimnames = list(
NULL, NULL))
一个简单的矩阵我想要得到的最低每列。
我会做这样的事情:
apply (test, 2, min)
> 107.65 NA NA 124.81 NA
但现在,让我们说,我想跳过NAs
。
第一列,我会做
min (test[,1], min(na.rm = TRUE))
> 107.65
但我不能用
apply (test, 2, min(na.rm = TRUE))
所以,我怎么传递参数给内部apply
的功能?
'apply(test,2,min,na.rm = T)'See this http:// stackoverflo w.com/questions/14427253/passing-several-arguments-to-fun-of-lapply-and-others-apply – ahly