2015-12-15 53 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]]) 
相关问题