我试图在三个带有名称的向量之间找到通用名称。我想在这三个向量中找到通用名称,并对这些通用命名向量的值进行计数(或求和)。
例如:
vec1<- c(1:20)
names(vec1) = c( "X13" , "X25", "X58", "X79", "X95" , "X118", "X212", "X311",
"X422" , "X536", "X899", "X1005","X1080" , "X1118", "X1322", "X1516","X1705"
, "X1890", "X1925", "X2008")
vec2<- c(21:40)
names(vec2) = c( "X11" , "X25", "X58", "X79", "X119" , "X120", "X212", "X311",
"X422" , "X536", "X899", "X995","X1080" , "X1098", "X1322", "X1516","X1705"
, "X1890", "X1930", "X2008")
vec3<- c(41:60)
names(vec3) = c( "X13" , "X25", "X58", "X79", "X95" , "X118", "X212", "X311",
"X422" , "X536", "X899", "X1005","X1080" , "X1118", "X1322", "X1516","X1705"
, "X1890", "X1925", "X2010")
在上面的示例中,在vec1,vec2和vec3中,“ x25”是通用名称,值分别为2,22和42。因此,输出应具有x25,其值为66(2 + 22 + 42 = 66)。
此外,“ x13”存在于vec1和vec3中,但不存在于vec2中。所以应该忽略它。
我尝试使用is.equal,但出现错误。
答案 0 :(得分:3)
我们可以将cmd /c @MyScript.bat & AdditionalCommands
与Reduce
一起使用,找出所有向量之间的通用名称,然后从所有向量中对它们进行子集化并添加它们。
intersect
答案 1 :(得分:1)
这里是library(tidyverse)
list(vec1, vec2, vec3) %>%
map_df(enframe, .id = 'vec') %>%
group_by(name) %>%
filter(n_distinct(vec) == 3) %>%
summarise(value = sum(value))
<LinearLayout>
<ScrollView/>
<ImageButton/>
</LinearLayout>