[R] Pattern matching and replacement in matrix
Gabor Grothendieck
ggrothendieck at gmail.com
Wed May 19 14:04:18 CEST 2010
Try this:
DF <- data.frame(a = head(letters), A = head(LETTERS))
DF[] <- lapply(DF, gsub, pattern = "a", replacement = "X")
m <- cbind(a = head(letters), A = head(LETTERS))
m[] <- gsub("a", "X", m)
In the future please provide test data and desired output as per
posting guide (see bottom of every post).
On Wed, May 19, 2010 at 6:35 AM, Dani Valverde <daniel.valverde at uab.cat> wrote:
> Hello,
> Is there any function like gsub(), that can match and replace patterns in a
> matrix or a data frame?
> Cheers!
>
> Dani
>
> --
> Daniel Valverde Saubí
>
> Grup de Biologia Molecular de Llevats
> Facultat de Veterinària de la Universitat Autònoma de Barcelona
> Edifici V, Campus UAB
> 08193 Cerdanyola del Vallès- SPAIN
>
> Tlf. +34 93 581 1910
> Fax: +34 93 581 1573
>
> ______________________________________________
> 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