→ cywhale: 如果寫 data[-which(VAL <= 5),] 符合你所要的嗎? 01/04 15:47
→ celestialgod: setdiff(data, data %>% filter(VAL < 6)) 01/04 16:07
→ celestialgod: data %>% setdiff(filter(., VAL < 6)) 01/04 16:12
→ celestialgod: setdiff後來dplyr有新增方法使用於data.frame 01/04 16:13
→ memphis: HI cywhale 根據經驗, 那樣寫如果which=0, 資料會爆掉喔 01/04 16:15
→ memphis: 要先 s <- which(VAL <= 5) 再判斷 if(!is.na(s[1])) 01/04 16:16
→ celestialgod: 疑問,為啥which會出現0? 01/04 16:21
→ celestialgod: which(data$VAL <= 5) 應該只會出現1~nrow(data)吧 01/04 16:21
→ memphis: 喔喔 感恩~ c大正解, 這樣寫起來就很dplyr style 01/04 16:22
→ memphis: 如果資料裡沒有<=5的 就會選空, 結果等於 integer(0) 01/04 16:23
→ memphis: 所以一般過which 我都會塞到一個s 然後判斷有沒有東西 01/04 16:25
→ celestialgod: 喔喔 你說NULL喔,我懂了!! 01/04 16:28
→ celestialgod: 我在想0是什麼XDD 01/04 16:28
→ celestialgod: setdiff配上%>%是真的滿dplyr style XD 01/04 16:29
→ memphis: 補充: 可是c大的方法好看, 速度非常慢 因為是df的setdiff 01/04 16:59
推 cywhale: ya 我忘記null這狀況,通常我也都會加個判斷式再做.. 01/04 17:00
→ memphis: data %>% slice(setdiff(1:nrow(.),which(VAL<6))) 01/04 17:03
→ memphis: 上面這個讓setdiff回到比兩個vector, 只是看起來就醜點 01/04 17:04
→ celestialgod: 不過看到cy大用-which就想說算了~~ 01/04 17:40
→ celestialgod: 原來有差異的QQ 01/04 17:42
推 cywhale: If original column contains "@" as memphis said 01/04 21:28
→ cywhale: then the column become character, and these solutions 01/04 21:29
→ cywhale: will differ from data[-which(VAL<=5),] for VAL='10' 01/04 21:30