问题描述
我有以下的数据叫GG和YY。
I have the following data called gg and yy.
> str(gg)
num [1:1992] 128 130 132 185 186 187 188 189 190 191 ...
> str(yy)
'data.frame': 2103 obs. of 2 variables:
$ grp : num 128 130 132 185 186 187 188 189 190 191 ...
$ predd: num -0.963 -1.518 1.712 -11.286 -8.195 ...
>
您会发现,GG的前几个值从YY比赛第几。
You'll notice that the first several values of gg match the first several from yy.
我想如果这个值YY $ GRP在GG的任何值匹配选择从YY行。问题是,GG和YY是不等长。此外,还有一些不在YY $ GRP present GG的一些值,也YY $ GRP的一些值未在$ GG p $ psent。
I would like to select rows from yy if the value yy$grp matches any value in gg. The issue is that gg and yy are of unequal length. Further, there are some values of gg that are not present in yy$grp and also some values of yy$grp not present in gg.
我似乎无法得到这个工作。它基本上是基于我所提到的指数值(GG,还是YY $ GRP)两个数据集的交集。
I can't seem to get this to work. It is basically an intersection of the two data sets based upon the index value I mentioned (gg, or yy$grp).
我试过:
inters<-intersect(gg,yy$grp)
yyint<-yy[yy$grp==inters,]
但得到以下
Warning message:
In yy$grp == inters :
longer object length is not a multiple of shorter object length
> str(yya)
'data.frame': 28 obs. of 2 variables:
$ grp : num 128 130 132 185 186 187 188 189 190 191 ...
$ predd: num -0.963 -1.518 1.712 -11.286 -8.195 ...
YYA应该是更长的时间,按照我的计划最少。
yya should be much longer, according to my plans at least.
感谢。
推荐答案
正如我所说,我认为这是你想要什么:
As I mentioned, I think this is what you want:
yy[yy$grp %in% gg,]
这篇关于在R,当阵列和mydataframe长度不相等选择从基于值数组mydataframe行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!