[R] changing character strings with hash marks

arun smartpink111 at yahoo.com
Thu Dec 13 23:16:23 CET 2012


Hi,
You could also use:

gsub("\\w","#","Mary plays football")
#[1] "#### ##### ########"
#or
gsub("[A-Za-z]", "#", "Mary plays football")

A.K.

----- Original Message -----
From: Uwe Ligges <ligges at statistik.tu-dortmund.de>
To: simona mancini <mancinisimona at yahoo.it>
Cc: "r-help at r-project.org" <r-help at r-project.org>
Sent: Thursday, December 13, 2012 5:38 PM
Subject: Re: [R] changing character strings with hash marks



On 13.12.2012 22:30, simona mancini wrote:
> Hi R users,
>
> I am quite new to R and I don't know how to deal with this (surely) easy issue. I need to replace words in sentences with as many hash marks as the number of characters per each word, as in the following example:
>
> Mary plays football
> #### ##### ########

gsub("[[:alpha:]]", "#", "Mary plays football")

Uwe Ligges


> Any suggestion about the function to be used?
> Thanks a lot.
>
> S.
>     [[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.
>

______________________________________________
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.





More information about the R-help mailing list