看板 R_Language 關於我們 聯絡資訊
- 問題: 當你想要問問題時,請使用這個類別 [問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [軟體熟悉度]: 請把以下不需要的部份刪除 新手(沒寫過程式,R 是我的第一次) [問題敘述]: 延續上個data frame 撈取特定資料問題,但是條件比較複雜 我需要c1 c2條件下的c3作為篩選條件 程式我嘗試用下面的方式敘述 但是沒有效果@@ 想請問哪邊需要修改 [程式範例]: df <- df[df$c3 %in% df[df$c1 >= '0.xxx' & df$c2 == 1,c3],] [關鍵字]: data frame select condition row column -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.132.153.20 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1459952193.A.A46.html
celestialgod: 這樣c3會undefine吧 而且'0.xxx'是字串耶 04/06 22:47
celestialgod: '0.xxx'改成數字,c3改成 'c3' 04/06 22:48
celestialgod: 原PO要不要學一下怎麼用dplyr? 04/06 22:49
celestialgod: df = df %>% filter(c3 %in% (df %>% filter(c1 >= 04/06 22:50
celestialgod: 0.xxx , c2 == 1) %>% .$c3)) 04/06 22:50
感謝C大,不過剛剛嘗試, R回應說 Error: could not find function "%>%" PS.抱歉 是自己環境沒安裝 dplyr 我再試試看
celestialgod: 板上搜尋dplyr可以找到相關教學文 04/06 22:51
ok~感謝提示,等等來研究一下dplyr的用法
joejoe14758: df <- df[ df[c1>=0.xxx] %in% df[c2==1] ] 04/06 23:52
感謝分享,不過R說error ※ 編輯: aee36900 (220.132.153.20), 04/07/2016 00:06:12 ※ 編輯: aee36900 (220.132.153.20), 04/07/2016 00:10:42
joejoe14758: 痾 那是用你上面的條件來作的... 04/07 01:00
joejoe14758: df [ df[df$c2==56]%in%df[df$c1>5000] ] 04/07 01:01