2015-12-15 57 views
0

我有一個帶有網址的數據框。例如:從數據框中刪除查詢字符串參數

"http://www.examplesite1.com?test=test" 
"http://www.examplesite2.com?test=test" 
"http://www.examplesite3.com?test=test" 
"http://www.examplesite4.com?test=test" 

的查詢參數是常見的,我想刪除它,有這樣的結果:

"http://www.examplesite1.com" 
"http://www.examplesite2.com" 
"http://www.examplesite3.com" 
"http://www.examplesite4.com" 
+0

'sub(「\\?test = test $」,「」,df $ url )'例如 – Cath

回答

4

您可以使用sub

vec <- c("http://www.examplesite1.com?test=test", 
     "http://www.examplesite2.com?a=b") 

sub("\\?.+", "", vec) 
# [1] "http://www.examplesite1.com" "http://www.examplesite2.com" 
1

嘗試:

df$MyCol <- sapply(df$MyCol, function(x) strsplit(x,"[?]")[[1]]) 
相關問題