考虑以下矢量资源和矩阵团队。 矢量res代表索引,我只需要提取那些索引号在vector res和gender =“F”中的名字。子集矩阵
我需要在R中这样做,因为我是R的新手,无法解决这个问题。
res
[1] 2 12 16 5 6 19 17 14 9 4
team
names genders
[1,] "aa" "M"
[2,] "ab" "M"
[3,] "al" "M"
[4,] "alp" "M"
[5,] "amr" "F"
[6,] "and" "M"
[7,] "an" "M"
[8,] "anv" "F"
[9,] "as" "M"
[10,] "ed" "M"
[11,] "neh" "F"
[12,] "pan" "M"
[13,] "poo" "F"
[14,] "ra" "M"
[15,] "roh" "M"
[16,] "shr" "F"
[17,] "sub" "M"
[18,] "val" "M"
[19,] "xi" "M"
我需要得到在矢量水库中的性别映射到“F”的那些指数的名称。因此,对于上述数据,我需要提取“shr”,因为它在矢量水库中,在[16,]矩阵团队中,性别是“F”。 – pbd 2012-04-13 00:16:35
团队[res,] [团队[res,] $性别=='F',] – aatrujillob 2012-04-13 00:36:30
@AndresT - 请注意 - 解决方案需要先将矩阵转换为data.frame。 – thelatemail 2012-04-13 00:51:22