我想检查是否all
elements
list
的A整除与list
B的所有元素,如果余数为0
所有elements
,我想print
A.如何将列表中的每个元素与R中另一个列表中的每个元素分开?
我的例子中的相应elements
到目前为止的代码
first<-c(2,4,6,8,10,12)
second<-c(2,3)
for (i in first){
for (j in second){
if (i%%j==0){ #if any elements in first is divisible by all elements in second
print(i)
}
}
}
但它给我的输出这样
[1] 2
[1] 4
[1] 6
[1] 6
[1] 8
[1] 10
[1] 12
[1] 12
我期待的东西[1] 6,12
不错!我正在考虑'第一个[第一个%% prod(second)== 0]',但是当'second'有点像'c(2,3,6)'时,这个问题就搞砸了。只是为了好玩,任何可以解决的方法? – Aramis7d