[R] gsub in data frame

Petr Pikal petr.pikal at precheza.cz
Wed Apr 5 14:38:50 CEST 2006


Hi

On 5 Apr 2006 at 7:48, Lapointe, Pierre wrote:

From:           	"Lapointe, Pierre" <Pierre.Lapointe at nbf.ca>
To:             	"'r-help at stat.math.ethz.ch'" <r-help at stat.math.ethz.ch>
Date sent:      	Wed, 5 Apr 2006 07:48:33 -0400
Subject:        	[R] gsub in data frame

> Hello,
> 
> I have this data frame:
> 
> ### begin
> 
> d <-data.frame(matrix(c("1","--","bla",2),2,2))
> d
> 
> # I want to replace the "--" by "\N" and still get a data frame.
> 
> # I tried: 
> 
> out <-gsub("--","\\\\N",as.matrix(d)) #using as.matrix to get rid of
> factors out cat(out)
> 
> # But I lost my data frame
> 
> ### end
> 
> Any idea?

re formate it back?

data.frame(matrix(out,2,2))
    X1  X2
 1   1 bla
 2 \\N   2

HTH
Petr


>
> 
> Regards,
> 
> Pierre Lapointe
> 
> **************************************************
> AVIS DE NON-RESPONSABILITE: Ce document transmis par
> courrie...{{dropped}}
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list