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? Regards, Pierre Lapointe ************************************************** AVIS DE NON-RESPONSABILITE: Ce document transmis par courrie...{{dropped}}
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.htmlPetr Pikal petr.pikal at precheza.cz
On Wed, 5 Apr 2006, Lapointe, Pierre wrote:> Hello, > > I have this data frame: > > ### begin > > d <-data.frame(matrix(c("1","--","bla",2),2,2)) > dSo d is a two-column data frame with factor columns.> # I want to replace the "--" by "\N" and still get a data frame.levels(d$X1) <- gsub("--","\\\\N", levels(d$X1))> # 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? > > 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 >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Seemingly Similar Threads
- Change the language of the labels in a graph
- How would you export a 3-dimensional array to an SQL database?
- grep searching for sequence of 3 consecutive upper case letters
- Gregexpr - extract results with lapply
- system(mysql... Does not recognize < as passing an attribute (No HTML)