[問題] data frame撈取資料-複雜條件

作者: aee36900 (持久戰!!)   2016-04-06 22:16:31
- 問題: 當你想要問問題時,請使用這個類別
[問題類型]:
程式諮詢(我想用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
作者: celestialgod (天)   2016-04-06 22:47:00
這樣c3會undefine吧 而且'0.xxx'是字串耶'0.xxx'改成數字,c3改成 'c3'原PO要不要學一下怎麼用dplyr?df = df %>% filter(c3 %in% (df %>% filter(c1 >=0.xxx , c2 == 1) %>% .$c3))板上搜尋dplyr可以找到相關教學文
作者: joejoe14758 (KILE)   2016-04-06 23:52:00
df <- df[ df[c1>=0.xxx] %in% df[c2==1] ]痾 那是用你上面的條件來作的...df [ df[df$c2==56]%in%df[df$c1>5000] ]

Links booklink

Contact Us: admin [ a t ] ucptt.com