Re: [问题] 在R中有处理http query string

楼主: celestialgod (天)   2017-06-13 18:45:46
前面先随便给他一个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

Links booklink

Contact Us: admin [ a t ] ucptt.com