Olivier ETERRADOSSI
2007-Feb-08 12:50 UTC
[R] Re : Re: setting a number of values to NA over a data.frame.
Hi again, Awfully sorry John, I should have been sleeping and did not see your full post.... here is a way, unless I miss the point again : fake<-as.data.frame(cbind(seq(1,10,by=1),c(rep(1,4),rep(0,4),rep(2,2)))) # from my previous post # one moree column this time ! fake3<-cbind(fake,fake$V2) index<-c(2,3) fake3[,index][fake3[,index]==0]<-NA not nice, but seems to do the job. Hope this helps... this time :-) Olivier -- 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 -------------- next part -------------- An embedded message was scrubbed... From: Olivier ETERRADOSSI <olivier.eterradossi at ema.fr> Subject: Re : Re: [R] setting a number of values to NA over a data.frame. Date: Thu, 08 Feb 2007 13:21:47 +0100 Size: 1685 Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070208/7faa5eef/attachment.mht
John Kane
2007-Feb-09 13:59 UTC
[R] Re : Re: setting a number of values to NA over a data.frame.
--- Olivier ETERRADOSSI <olivier.eterradossi at ema.fr> wrote:> Hi again, > > Awfully sorry John, I should have been sleeping and > did not see your > full post.... > > here is a way, unless I miss the point again : > >fake<-as.data.frame(cbind(seq(1,10,by=1),c(rep(1,4),rep(0,4),rep(2,2))))> > # from my previous post > > # one moree column this time ! > fake3<-cbind(fake,fake$V2) > index<-c(2,3) > fake3[,index][fake3[,index]==0]<-NA > > not nice, but seems to do the job. > Hope this helps... this time :-) > OlivierThat looks like it and is similar to one Haris suggested. I think I was messing up the fake3[,index] reference somehow. I need to make my explanations a bit clearer. Thanks> > > Date: Thu, 08 Feb 2007 13:21:47 +0100 > From: Olivier ETERRADOSSI > <olivier.eterradossi at ema.fr> > To: r-help at stat.math.ethz.ch > Subject: Re : Re: [R] 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 > > >
Maybe Matching Threads
- about scagnostics
- I might be dumb : a simple question about "foreach"
- behaviour of xls2sep when running read.xls (package gdata) sinceupgrade of R
- Generate a serie of new vars that correlate with existingvar
- how to convert the lower triangle of a matrix to a symmetricmatrix