I would like to iterate over a a list of combinations of filters that are applied to the multiple columns of a dataframe that looks like this:
df <- data.frame(
ID1 = c("Asset1", "Asset2", "Asset1", "Asset2", "Asset1", "Asset2", "Asset1", "Asset2"),
ID2 = c("Asset1", "Asset1", "Asset2", "Asset2", "Asset1", "Asset1", "Asset2", "Asset2"),
var1= c(0.011, 0.012, 0.012, 0.022, .0011, 0.0012, 0.0012, 0.0022)
)
An example:
我要赞扬var1对以下组合的价值:
filter1: ID1== Asset1 and ID2== Asset1
and
filter2: ID1== Asset1 and ID2== Asset2
仅对一种组合而言,我就能够用一种yr子过滤器作此处理:
df %>% filter(ID1== Asset1 , ID2== Asset1 )
但是,我要用一种 lo子来做到这一点,它会渗透到所有过滤器上:
filter_list<- c(filter1, filter2)
for (filter_i in filter_list){
df %>% filter(filter_i)
}