[R] case conversion and/or string comparison
Kaspar Pflugshaupt
pflugshaupt at geobot.umnw.ethz.ch
Fri Nov 16 13:45:00 CET 2001
On 16.11.2001 12:37 Uhr, Randall Skelton wrote:
> This is no doubt trivial but after searching the help files and the web, I
> cannot seem to find it.
>
> 1) How do I convert 'hgt' into 'HGT' in R?
There are the functions tolower() and toupper(). They work as one would
expect:
> toupper("hgt")
[1] "HGT"
With either of them, the comparison you mention is easy:
compareCaseless <- function(string1, string2)
return(toupper(string1) == toupper(string2))
> compareCaseless("hgt", "HGT")
[1] TRUE
> 2) How should I have used the help facilities to find this?
>
Hmm. help.search("case") does not give them, nor does help.search("string").
Nor do, in fact, help.search("upper") or "lower". I just found them
indirectly via help.search("character"), which mentioned the chartr()
function. On its help page, those two functions are noted.
Maybe they deserve to be better advertised?
Cheers
Kapar Pflugshaupt
--
Kaspar Pflugshaupt
Geobotanisches Institut
Zuerichbergstr. 38
CH-8044 Zuerich
Tel. ++41 1 632 43 19
Fax ++41 1 632 12 15
mailto:pflugshaupt at geobot.umnw.ethz.ch
privat:pflugshaupt at mails.ch
http://www.geobot.umnw.ethz.ch
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list