[R] replace "%" with "\%"

Liviu Andronic landronimirc at gmail.com
Fri May 15 17:36:08 CEST 2009


Thanks all for the prompt responses. Now Hmisc::latex() no longer
generates errors on Rcmdr::numSummary() objects (with `tempa' below
being such an object).
> colnames(tempa$table) <- gsub("%", "\\%", colnames(tempa$table), fixed=TRUE)
> latex(tempa$table, cdec=3)

Best regards,
Liviu


On Fri, May 15, 2009 at 5:13 PM, Patrick Burns <pburns at pburns.seanet.com> wrote:
> See 'The R Inferno' page 46.
>
>
>
> Patrick Burns
> patrick at burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of "The R Inferno" and "A Guide for the Unwilling S User")
>
> Liviu Andronic wrote:
>>
>> Dear all,
>> I'm trying to gsub() "%" with "\%" with no obvious success.
>>>
>>> temp1 <- c("mean", "sd",   "0%",   "25%",  "50%",  "75%",  "100%")
>>> temp1
>>
>> [1] "mean" "sd"   "0%"   "25%"  "50%"  "75%"  "100%"
>>>
>>> gsub("%", "\%", temp1, fixed=TRUE)
>>
>> [1] "mean" "sd"   "0%"   "25%"  "50%"  "75%"  "100%"
>> Warning messages:
>> 1: '\%' is an unrecognized escape in a character string
>> 2: unrecognized escape removed from "\%"
>>
>> I am not quite sure on how to deal with this error message. I tried
>> the following
>>>
>>> gsub("%", "\\%", temp1, fixed=TRUE)
>>
>> [1] "mean"   "sd"     "0\\%"   "25\\%"  "50\\%"  "75\\%"  "100\\%"
>>
>> Could anyone suggest how to obtain output similar to:
>> [1] "mean"   "sd"     "0\%"   "25\%"  "50\%"  "75\%"  "100\%"
>>
>> Thank you,
>> Liviu
>>
>>
>>
>



-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail




More information about the R-help mailing list