Re: [S] A casefold() function that caps only the first character

Patrick Connolly (PConnolly@grunt.marc.cri.nz)
Thu, 17 Sep 1998 10:19:00 +1200 (NZST)


According to Bill Venables:

|> I think John's function suggests the operation is much more
|> complicated than it need be. Here is a simpler function that
|> does the same job.
|>
|> Updown <- function(cv) {
|> cv <- casefold(cv)
|> first <- substring(cv, 1, 1)
|> alpha <- !is.na(match(first, letters))
|> first[alpha] <- LETTERS[match(first[alpha], letters)]
|> paste(first, substring(cv, 2), sep="")
|> }

Why do we need the alpha? NAs don't seem to matter.

cv <- casefold(cv)
first <- substring(cv, 1, 1)
FIRST_casefold(first,upper=T)
paste(FIRST, substring(cv, 2), sep = "")

> Updown(c("ruBBi-sh","?bananas","Ca\R**RO!!T"))
[1] "Rubbi-sh" "?bananas" "Car**ro!!t"

seems to cover everything except the "\" but the alpha doesn't get
that one either. Would that present a problem to anyone?

Patrick

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news