Olivier ETERRADOSSI
2007-Feb-08 12:21 UTC
[R] Re : Re: setting a number of values to NA over a data.frame.
Hi John, Unless I miss a point, why dont you try something like : # some fake data > fake<-as.data.frame(cbind(seq(1,10,by=1),c(rep(1,4),rep(0,4),rep(2,2)))) V1 V2 1 1 1 2 2 1 3 3 1 4 4 1 5 5 0 6 6 0 7 7 0 8 8 0 9 9 2 10 10 2 # change 0 by NA > fake[fake==0]<-NA # or fake$V2[fake$V2==0]<-NA if you don't want all 0 in the dataframe to be changed to NA # test > is.na(fake$V2) [1] FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE FALSE FALSE Sorry if I did not understand the issue. Hope this helps. Olivier Jim Lemon wrote :> John Kane wrote: > >> > This is probably a simple problem but I don't see a >> > solution. >> > >> > I have a data.frame with a number of columns where I >> > would like 0 <- NA >> > >> > Hi John, > You might have a look at "toNA" in the prettyR package. Wait for version > 1.0-4, just uploaded, as I have fixed a bug in that function. > > Jim-- Olivier ETERRADOSSI Ma?tre-Assistant CMGD / Equipe "Propri?t?s Psycho-Sensorielles des Mat?riaux" Ecole des Mines d'Al?s H?lioparc, 2 av. P. Angot, F-64053 PAU CEDEX 9 tel std: +33 (0)5.59.30.54.25 tel direct: +33 (0)5.59.30.90.35 fax: +33 (0)5.59.30.63.68 http://www.ema.fr
Prof Brian Ripley
2007-Feb-08 13:26 UTC
[R] Re : Re: setting a number of values to NA over a data.frame.
I think you do understand it. Indexing a data frame by a logical matrix is provided just for applications like this and the reverse, mydf[is.na(mydf)] <- something prettyR's toNA seems to believe that data frames can be other than 2D, which is surprising. On Thu, 8 Feb 2007, Olivier ETERRADOSSI wrote:> Hi John, > > Unless I miss a point, why dont you try something like : > > # some fake data > > fake<-as.data.frame(cbind(seq(1,10,by=1),c(rep(1,4),rep(0,4),rep(2,2)))) > V1 V2 > 1 1 1 > 2 2 1 > 3 3 1 > 4 4 1 > 5 5 0 > 6 6 0 > 7 7 0 > 8 8 0 > 9 9 2 > 10 10 2 > > # change 0 by NA > > fake[fake==0]<-NA # or fake$V2[fake$V2==0]<-NA if you don't want all > 0 in the dataframe to be changed to NA > # test > > is.na(fake$V2) > [1] FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE FALSE FALSE > > Sorry if I did not understand the issue. Hope this helps. Olivier > > > Jim Lemon wrote : > >> John Kane wrote: >> >>>> This is probably a simple problem but I don't see a >>>> solution. >>>> >>>> I have a data.frame with a number of columns where I >>>> would like 0 <- NA >>>> >>> >> Hi John, >> You might have a look at "toNA" in the prettyR package. Wait for version >> 1.0-4, just uploaded, as I have fixed a bug in that function. >> >> Jim > >-- 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
- Re : Re: setting a number of values to NA over a data.frame.
- about scagnostics
- behaviour of xls2sep when running read.xls (package gdata) sinceupgrade of R
- problem with rJava : same as message from wwreith on Mon, 27 Jun 2011
- I might be dumb : a simple question about "foreach"