[R] String manipulation

David Winsemius dwinsemius at comcast.net
Sat May 8 16:30:28 CEST 2010


On May 8, 2010, at 10:05 AM, Webby wrote:

>
> Dear community,
>
> I have a problem with a string conversion:
>
>> text
> [1] ""                   "and"                "\xc1d\xe1m"
> [4] "graphical"          "interface"          "MLP"
> [7] "Nagy"               "networks"           "Networks"
> [10] "neural"             "Neural"             "RBF"
> [13] "<sodzsu at yahoo.com>" "user"               "with"
> [16] "and"                "\xc1d\xe1m"         "graphical"
> [19] "interface"          "MLP"
>>
>
> I need to get rid off text[3,17] !

Does this work>

text[ grep("[[:alnum:]]|", text) ]


Still gives the warnings but seems to properly leave out the "control- 
sequences".

> I have this kind of control-sequence a few times in my text and I do  
> not get
> rid of it, by strsplit or sub.
>
>> grep("\xc1d\xe1m",text)
> Error in grep("\xc1d\xe1m", text) :
>  regular expression is invalid in this locale
>> grep("\\xc1d\\xe1m",text)
> integer(0)
> Warning messages:
> 1: In grep("\\xc1d\\xe1m", text) :
>  input string 3 is invalid in this locale
> 2: In grep("\\xc1d\\xe1m", text) :
>  input string 17 is invalid in this locale
>
> Thanks in advance,
> Georg
>
> ______________________________________________
> 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



More information about the R-help mailing list