我有一个数据帧列表
listofdf <- list(a = a, b = b, c = c)我有一个功能:
remove_outliers <- function(x, ll, ul) {
require(dplyr)
x <- x %>% filter(SALES < quantile(SALES, probs = c(ll)) & SALES > quantile(SALES, probs = c(ul)))
return(x)
}我想在列表上应用这个函数。条件是,参数ul、和 ll 的值对于列表中的每个元素都会发生变化。
I不能写: lapply(listofdf, remove_outliers, 0.01, 0.99),因为0.01-0.99的变化取决于df。
我预感到可以使用Map或mapply解决这个问题,因此我尝试了以下方法:
listofdf <- Map(remove_outliers, listofdf, MoreArgs = list(ll = c(0.1, 0.2, 0.3), ul = c(0.90, 0.95, 0.99)))
但我有错误:
Warning messages:
1: In filter_impl(.data, dots) :
longer object length is not a multiple of shorter object length
2: In filter_impl(.data, dots) :
longer object length is not a multiple of shorter object length
3: In filter_impl(.data, dots) :
longer object length is not a multiple of shorter object length
4: In filter_impl(.data, dots) :
longer object length is not a multiple of shorter object length发布于 2015-12-10 21:50:21
在这里,我尝试了一个虚拟的removeOutlier函数
remove_outliers <- function(x, ll, ul) {
return(x>ll & x< ul)
}
listofdf <- list(a = 1:10, b = 100:120, c = 1000:1010)
filt<- mapply( FUN=remove_outliers, listofdf ,
ll=c(2,102,1004), ul=c(8,117,1008) )
res<- mapply(FUN="[", listofdf,filt)
res 发布于 2015-12-10 22:07:19
你传递论点的方式可能有问题。只需尝试:
mapply(remove_outilers, l, ll = c(0.1, 0.2, 0.3), ul = c(0.90, 0.95, 0.99))发布于 2015-12-10 21:42:59
为什么不绑定到一个数据文件中呢?
big_data =
listofdf %>%
bind_rows(.id = "source")https://stackoverflow.com/questions/34211802
复制相似问题