考慮以下矢量資源和矩陣團隊。 矢量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