Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make a function which change lowercase to uppercase and vice verse?

Can you please help, how to write a function which change little letters to big and vice verse in R?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Example string

mystring = "This Is aN ExAmPlE sTRING"

See ?chartr for details but its used like this chartr(old,new,x). Here we are flipping the lower case and uppercase letters so the old is the reverse of the new and what we want to change (x) is the string.
Function:

myfunct <- function(string){
  chartr("a-zA-Z", "A-Za-z",string)
}

call function:

myfunct(mystring)

Output:

[1] "tHIS iS An eXaMpLe String"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading