Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert "space" into "%20" with R

Tags:

curl

r

rcurl

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.

like image 703
Kai Feng Chew Avatar asked Jun 20 '12 09:06

Kai Feng Chew


People also ask

How does GSUB work in R?

The gsub() function in R is used for replacement operations. The functions takes the input and substitutes it against the specified values. The gsub() function always deals with regular expressions. You can use the regular expressions as the parameter of substitution.

How do I remove spaces from a column name in R?

The easiest option to replace spaces in column names is with the clean. names() function. This R function creates syntactically correct column names by replacing blanks with an underscore. Moreover, you can use this function in combination with the %>%-operator from the Tidyverse package.

How do I replace multiple characters in a string in R?

Use str_replace_all() method of stringr package to replace multiple string values with another list of strings on a single column in R and update part of a string with another string.


1 Answers

Another option would be URLencode():

y <- "I love you"
URLencode(y)
[1] "I%20love%20you"
like image 70
plannapus Avatar answered Oct 03 '22 11:10

plannapus