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
Exactly how do you want to do that? (PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.) Provide a before/after example of what you want. You could use the 'apply' functions. 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Hi, I think you can make it work by combining gsub() and sapply() (or lapply()), though I don't really know how (those *apply() functions are still kind of a mystery for me). Maybe someone else can help you Ivan Le 5/19/2010 12:35, Dani Valverde a ?crit :> Hello, > Is there any function like gsub(), that can match and replace patterns > in a matrix or a data frame? > Cheers! > > Dani >-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php
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. >