[R] remove leading slash
peter dalgaard
pdalgd at gmail.com
Fri Jun 8 19:53:50 CEST 2012
On Jun 8, 2012, at 19:25 , David Winsemius wrote:
>
> On Jun 8, 2012, at 1:11 PM, Ben quant wrote:
>
>> Hello,
>>
>> How do I change this:
>>> cnt_str
>> [1] "\002" "\001" "\102"
>>
>> ...to this:
>>> cnt_str
>> [1] "2" "1" "102"
>>
>> Having trouble because of this:
>>> nchar(cnt_str[1])
>> [1] 1
>
> "\001" is ASCII cntrl-A, a single character.
>
> ?Quotes # not the first, second or third place I looked but I knew I had seen it before.
>
However, if you insist, this seems to do it:
> as.character(as.octmode(as.integer(charToRaw(paste(x,collapse="")))))
[1] "002" "001" "102"
> str(as.character(as.octmode(as.integer(charToRaw(paste(x,collapse=""))))))
chr [1:3] "002" "001" "102"
> x
[1] "\002" "\001" "B"
(NB Octal code "\102" is a "B".)
Or, as I suspect the above is doing internally:
> sprintf("%03o", as.integer(charToRaw(paste(x,collapse=""))))
[1] "002" "001" "102"
-pd
>
>>
>> Thanks!
>>
>> Ben
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list