问题
Referring the title, I'm figuring how to convert space between words to be %20 .
For example,
> y <- "I Love You"
How to make y = I%20Love%20You
> y
[1] "I%20Love%20You"
Thanks a lot.
回答1:
gsub()
is one option:
R> gsub(pattern = " ", replacement = "%20", x = y)
[1] "I%20Love%20You"
回答2:
Another option would be URLencode()
:
y <- "I love you"
URLencode(y)
[1] "I%20love%20you"
回答3:
The function curlEscape()
from the package RCurl
gets the job done.
library('RCurl')
y <- "I love you"
curlEscape(urls=y)
[1] "I%20love%20you"
来源:https://stackoverflow.com/questions/11116446/how-to-convert-space-into-20-with-r