Hello I almost got through the problem in post "aggregation of irregular interval time-series" I just don't understand how to fix that when I try '' with(datatable,ifelse(is.na(x),y,x)) '' if y is na replaces me with 0 and not with na Thank you -- Perito agrario Enrico Gabrielli Tessera n. 633 Collegio Periti agrari prov. Di Modena Biblioteca agricoltura: https://www.zotero.org/groups/aplomb/ https://it.linkedin.com/pub/enrico-gabrielli/9a/186/159 https://enricogabrielli76.wordpress.com/ https://www.inaturalist.org/observations/bonushenricus skype: enricogabrielli (enricogabrielli76.peragr at gmail.com)
reprex? Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Jun 11, 2021 at 7:23 AM Enrico Gabrielli < enricogabrielli76.peragr at gmail.com> wrote:> Hello > I almost got through the problem in post "aggregation of irregular > interval time-series" > I just don't understand how to fix that when I try > '' > with(datatable,ifelse(is.na(x),y,x)) > '' > if y is na > replaces me with 0 > and not with na > > Thank you > -- > Perito agrario Enrico Gabrielli > Tessera n. 633 Collegio Periti agrari prov. Di Modena > Biblioteca agricoltura: https://www.zotero.org/groups/aplomb/ > https://it.linkedin.com/pub/enrico-gabrielli/9a/186/159 > https://enricogabrielli76.wordpress.com/ > https://www.inaturalist.org/observations/bonushenricus > skype: enricogabrielli (enricogabrielli76.peragr at gmail.com) > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >[[alternative HTML version deleted]]
Hi, I did not follow your previous post but your code looks confusing to me with(datatable,ifelse(is.na(x),y,x)) Why do you have 'x' in the first place if all you want is to do the operation on y? It's like you want to count how many apples you have but your eyes are looking at peaches. Please rethink your code and what you want to achieve. Best, Jiefei On Fri, Jun 11, 2021 at 10:23 PM Enrico Gabrielli <enricogabrielli76.peragr at gmail.com> wrote:> > Hello > I almost got through the problem in post "aggregation of irregular > interval time-series" > I just don't understand how to fix that when I try > '' > with(datatable,ifelse(is.na(x),y,x)) > '' > if y is na > replaces me with 0 > and not with na > > Thank you > -- > Perito agrario Enrico Gabrielli > Tessera n. 633 Collegio Periti agrari prov. Di Modena > Biblioteca agricoltura: https://www.zotero.org/groups/aplomb/ > https://it.linkedin.com/pub/enrico-gabrielli/9a/186/159 > https://enricogabrielli76.wordpress.com/ > https://www.inaturalist.org/observations/bonushenricus > skype: enricogabrielli (enricogabrielli76.peragr at gmail.com) > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
On Fri, 11 Jun 2021 16:15:06 +0200 Enrico Gabrielli <enricogabrielli76.peragr at gmail.com> wrote:> Hello > I almost got through the problem in post "aggregation of irregular > interval time-series" > I just don't understand how to fix that when I try > '' > with(datatable,ifelse(is.na(x),y,x)) > '' > if y is na > replaces me with 0 > and not with na > > Thank youWorks fine for me. There's something going on that you're not telling us or have messed up. Example: x <- 1:10 x[c(1,3,5)] <- NA y <- (1:10)/10 y[c(3,5,7)] <- NA mung <- data.frame(x=x,y=y) gorp <- with(mung,ifelse(is.na(x),y,x)) cbind(mung,result=gorp) No spurious zeroes. Note however that this is yet another example of the unnecessary use of ifelse(). Much better is: gorp2 <- x i <- is.na(x) gorp2[i] <- y[i] Check: all.equal(gorp,gorp2) # TRUE As has been pointed out, you should include a minimal reproducible example in questions such as this. Creating such an example almost always reveals the source of the problem so that you can solve it yourself. cheers, Rolf Turner -- Honorary Research Fellow Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276