看板 R_Language 關於我們 聯絡資訊
前面先隨便給他一個protocle跟host 加個?表示是query string 然後用httr::parse_url就可以輕鬆處理完了 剩下就是看你要什麼欄位mapping到table中,改個名字,然後as.data.frame即可 library(httr) x <- parse_url(paste0("http://1?", "utm_source=apple&utm_campaign=PRO&", "utm_medium=banner&text_id=12228473&date=970101&", "loc=65173194cbfdbb89e06742a196ec150f")) x$query # $utm_source # [1] "apple" # # $utm_campaign # [1] "PRO" # # $utm_medium # [1] "banner" # # $text_id # [1] "12228473" # # $date # [1] "970101" # # $loc # [1] "65173194cbfdbb89e06742a196ec150f" ※ 引述《jklkj (誠實可靠小郎君)》之銘言: : [問題類型]: : 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) : [軟體熟悉度]: : 入門(寫過其他程式,只是對語法不熟悉) : [問題敘述]: : 目前我有A、B兩個table : 我想做一件事是把兩個table先join成C,這部分沒問題我用merge : 之後我想當item欄位是空值時把text的資料擷取出部分 : text的資料是url類似 : utm_source=apple&utm_campaign=PRO&utm_medium=banner&text_id=12228473&date= : 970101&loc=65173194cbfdbb89e06742a196ec150f : 我想把各別的字串丟進資料庫的欄位中 : 例如: : apple 丟進source欄位 : PRO丟進campaign欄位 : banner丟進medium欄位 : 65173194cbfdbb89e06742a196ec150f丟進loc欄位 : 但是text_id我沒有設欄位,所以不需要解析 : [程式範例]: : if(C$item == "") {C$apple <- C$text} : 我本來是想說先丟進去再拆解,可是我連這個最基礎的都ERROR : the condition has length > 1 and only the first element will be used : 想問一下這怎麼處理 : [環境敘述]: : R version 3.3.3 (2017-03-06) : Platform: x86_64-w64-mingw32/x64 (64-bit) : Running under: Windows 7 x64 (build 7601) Service Pack 1 : locale: : [1] LC_COLLATE=Chinese (Traditional)_Taiwan.950 LC_CTYPE=Chinese (Traditional)_Taiwan.950 : [3] LC_MONETARY=Chinese (Traditional)_Taiwan.950 LC_NUMERIC=C : [5] LC_TIME=Chinese (Traditional)_Taiwan.950 : attached base packages: : [1] stats graphics grDevices utils datasets methods base : other attached packages: : [1] RPostgreSQL_0.4-1 DBI_0.6 : loaded via a namespace (and not attached): : [1] tools_3.3.3 : [關鍵字]: : ETL -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.235.47.89 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1497350749.A.7EA.html ※ 編輯: celestialgod (36.235.47.89), 06/13/2017 18:46:47