> -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Heikki Kaskelma > Sent: Monday, August 29, 2011 6:13 PM > To: r-h...@stat.math.ethz.ch > Subject: Re: [R] weird apply() behavior > > "array chip": > >Hi, I had a weird results from using apply(). > > Consider: > > y<-data.frame(list(a=c(1,NA), b=c('2k','0'))) > do.call(args=y, > Vectorize(v=c("a","b"), > function(a,b) if(is.na(z<-b=="2k" & a==1)) 0 > else z+0))
I find the following easier to understand, but there is no accounting for taste. It is faster, by a factor of c. 50 when y is blown up to have 10000 rows. > with(y, as.integer(!is.na(b) & b=="2k" & !is.na(a) & a==1)) [1] 1 0 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > > Heikki Kaskelma > Munkkiniemi > > ______________________________________________ > R-help@r-project.org mailing list > 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. ______________________________________________ R-help@r-project.org mailing list 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.