Mulholland, Tom
2003-May-14 05:24 UTC
[R] Is there a simple method of changing text into 'Proper Ca se'
Yes and no. Given your response it appears that "Proper Case" is not a term that everyone uses. In Excel there is a function "Proper" which in essence changes "this line into something like this" into "This Line Into Something Like This." My look at casefold seesm to be that is is a wrapper of two functions to change text into either Lower or Upper case.So my question is about how do you just capitalise the first letter in each word. Thanks for your response. Tom -----Original Message----- From: Spencer Graves [mailto:spencer.graves at PDF.COM] Sent: Wednesday, 14 May 2003 12:51 PM To: Mulholland, Tom Cc: ' (r-help at stat.math.ethz.ch)' Subject: Re: [R] Is there a simple method of changing text into 'Proper Case' It's not obvious to me what you are asking, but I'm guessing that "casefold" might help. hth. spencer graves Mulholland, Tom wrote:> I am probably just looking in the wrong place. I am sure there are a > number of ways to do this. If anyone could point me in the right > direction it would be very much appreciated. > > Thanks > > _________________________________________________ > > Tom Mulholland > Senior Policy Officer > WA Country Health Service > 189 Royal St, East Perth, WA, 6004 > > Tel: (08) 9222 4062 > e-mail: Tom.Mulholland at health.wa.gov.au > <mailto:Tom.Mulholland at health.wa.gov.au> > > The contents of this e-mail transmission are confidential and may be > protected by professional privilege. The contents are intended only > for the named recipients of this e-mail. If you are not the intended > recipient, you are hereby notified that any use, reproduction, > disclosure or distribution of the information contained in this e-mail > is prohibited. Please notify the sender immediately. > > > [[alternate HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Uwe Ligges
2003-May-14 06:40 UTC
[R] Is there a simple method of changing text into 'Proper Ca se'
Mulholland, Tom wrote:> Yes and no. Given your response it appears that "Proper Case" is not a term > that everyone uses. In Excel there is a function "Proper" which in essence > changes "this line into something like this" into "This Line Into Something > Like This." > > My look at casefold seesm to be that is is a wrapper of two functions to > change text into either Lower or Upper case.So my question is about how do > you just capitalise the first letter in each word.Perl experts might do it differently, but the "R way" seems to be substring(x, 1, 1) <- toupper(substring(x, 1, 1)) substring(x, 2) <- tolower(substring(x, 2)) Uwe Ligges> Thanks for your response. > > Tom > > -----Original Message----- > From: Spencer Graves [mailto:spencer.graves at PDF.COM] > Sent: Wednesday, 14 May 2003 12:51 PM > To: Mulholland, Tom > Cc: ' (r-help at stat.math.ethz.ch)' > Subject: Re: [R] Is there a simple method of changing text into 'Proper > Case' > > > It's not obvious to me what you are asking, but I'm guessing that > "casefold" might help. > > hth. spencer graves > > Mulholland, Tom wrote: > >>I am probably just looking in the wrong place. I am sure there are a >>number of ways to do this. If anyone could point me in the right >>direction it would be very much appreciated. >> >>Thanks >> >>_________________________________________________ >> >>Tom Mulholland >>Senior Policy Officer >>WA Country Health Service >>189 Royal St, East Perth, WA, 6004 >> >>Tel: (08) 9222 4062 >>e-mail: Tom.Mulholland at health.wa.gov.au >><mailto:Tom.Mulholland at health.wa.gov.au>
Mulholland, Tom
2003-May-15 06:23 UTC
[R] Is there a simple method of changing text into 'Proper Ca se'
Thank you for the help. As a result I have written two functions. SentCase <- function(InputString){ InputString <- paste(toupper(substring(InputString,1,1)),tolower(substring(InputString,2)), sep="") } ProperCase <- function(InputString){ sapply(lapply(strsplit(InputString," "), SentCase), paste, collapse=" ") } > cat(SentCase("this little string")) This little string> > cat(ProperCase("this little string")) This Little String> -----Original Message----- From: Uwe Ligges [mailto:ligges at statistik.uni-dortmund.de] Sent: Wednesday, 14 May 2003 2:40 PM To: Mulholland, Tom Cc: 'Spencer Graves'; (r-help at stat.math.ethz.ch) Subject: Re: [R] Is there a simple method of changing text into 'Proper Ca se' Mulholland, Tom wrote:> Yes and no. Given your response it appears that "Proper Case" is not a > term that everyone uses. In Excel there is a function "Proper" which > in essence changes "this line into something like this" into "This > Line Into Something Like This." > > My look at casefold seesm to be that is is a wrapper of two functions > to change text into either Lower or Upper case.So my question is about > how do you just capitalise the first letter in each word.Perl experts might do it differently, but the "R way" seems to be substring(x, 1, 1) <- toupper(substring(x, 1, 1)) substring(x, 2) <- tolower(substring(x, 2)) Uwe Ligges> Thanks for your response. > > Tom > > -----Original Message----- > From: Spencer Graves [mailto:spencer.graves at PDF.COM] > Sent: Wednesday, 14 May 2003 12:51 PM > To: Mulholland, Tom > Cc: ' (r-help at stat.math.ethz.ch)' > Subject: Re: [R] Is there a simple method of changing text into 'Proper > Case' > > > It's not obvious to me what you are asking, but I'm guessing that > "casefold" might help. > > hth. spencer graves > > Mulholland, Tom wrote: > >>I am probably just looking in the wrong place. I am sure there are a >>number of ways to do this. If anyone could point me in the right >>direction it would be very much appreciated. >> >>Thanks >> >>_________________________________________________ >> >>Tom Mulholland >>Senior Policy Officer >>WA Country Health Service >>189 Royal St, East Perth, WA, 6004 >> >>Tel: (08) 9222 4062 >>e-mail: Tom.Mulholland at health.wa.gov.au >><mailto:Tom.Mulholland at health.wa.gov.au>