推 andrew43: 我建議直接列舉所有直轄市的區名去抓,比純靠reg exp的 08/05 16:49
→ andrew43: 邏輯還穩當。 08/05 16:49
推 locka: 推Andrew大!有的區是三個字(ex:那瑪夏區)直接用清單比對比 08/05 16:59
推 locka: 較不會錯 08/05 16:59
→ love11098787: 這筆資料只有台北市的,看過區應該都剛好是三個字 08/05 17:31
→ andrew43: 補上code,包括之後檢查的方向。 08/05 18:07
→ love11098787: 感謝A大!!!成功了 08/05 21:49
→ love11098787: 遇到character(0)要怎麼刪除,我用data[length(dat 08/06 09:54
→ love11098787: a$region)>0]發現刪不掉 08/06 09:54
→ andrew43: `data`是list嗎?用雙重中括號 08/06 14:33
→ andrew43: 更正,試試在我的code後res[sapply(res, length) != 0] 08/06 14:37
→ love11098787: data是資料框 08/06 14:49
→ love11098787: character(0)還是無法刪除 08/06 14:57
→ andrew43: 請以code重現你的操作。 08/06 15:04
→ love11098787: data$region[sapply(data$region,length)!=0] 08/06 15:16
→ andrew43: 沒有完整重現困難的code與假資料實在無能為力 08/06 15:28
→ andrew43: 試試用x<-character(0); identical(x, character(0))去 08/06 15:58
→ andrew43: 一個一個檢驗。x應對應一個cell而非一整個column。 08/06 15:58
→ love11098787: 找到方法了,在前面資料處理的時候拿掉不要的字串 08/06 17:31
→ love11098787: ,之後就不會出現了,感謝你! 08/06 17:31