[問題] match找不到數值

看板R_Language作者 (AL)時間6年前 (2018/06/27 16:44), 6年前編輯推噓0(003)
留言3則, 2人參與, 6年前最新討論串1/1
這是一段來自於github上的一段程式碼 其中samples=c("A_r","A_ir","B_r","B_ir",...) reps <- grep("_r|_ir",samples,value=TRUE) # get the replicates (ending with _r or _ir) samps <- match(sub("_r|_ir","",reps),samples) # match against its sample (ie names w/o _r or _ir) 不過我照著執行後samps只會出現一堆NA 想問這是怎麼回事? -- Sent from my Windows -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.122.136.81 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1530089084.A.717.html

06/27 18:15, 6年前 , 1F
因為找不到相等者所以回傳NA。
06/27 18:15, 1F

06/28 11:20, 6年前 , 2F
因為有用 sub 把 _r 或 _ir 刪除,所以 match 不到?!
06/28 11:20, 2F
原文上面寫的 我也覺得很奇怪 ※ 編輯: k97231 (140.122.152.43), 07/02/2018 09:36:46

07/08 03:17, 6年前 , 3F
你想想如果samples中有任何"A"或"B"會如何?
07/08 03:17, 3F
文章代碼(AID): #1RCqvySN (R_Language)
文章代碼(AID): #1RCqvySN (R_Language)