Skip to content
Prev 360182 / 398503 Next

Bug in by() function which works for some FUN argument and does not work for others

Dear All,

Yes, I certainly now agree with the suggestion of Adrian Dusa for using
colMeans in place of mean in the situation that I had reported to r-help.
And I am sorry that I did not personally extend my thanks to him. I really
wish to thank him for his suggestion, and I do this now.

However, I wished for future a way to apply a more complex function than
mean, say, e.g. a function for skewness or kurtosis and the likes in the
by() function. The function colMeans would be applicable for mean only.
That is why, I later came to above solution.

Yet, during all these deliberations, I wish to mention the suggestion given
by Dr. Jim Lemon, who suggested to use following code mixing by() into
sapply() wonderfully taking advantage of positional interpretations of
arguments in any R-code, that actually met my objective nicely for my
future project of using more complex functions in lieu of mean:

sapply(brain[,-1],by,brain$Gender,mean,na.rm=TRUE)
       FSIQ    VIQ    PIQ   Weight   Height MRI_Count
Female 111.9 109.45 110.45 137.2000 65.76500  862654.6
Male   115.0 115.25 111.60 166.4444 71.43158  954855.4

Secondly, I also wish to express my sorry to have mentioned "bug" for the
by() function, instead of thinking that I could be my mistake, whereas I
should have plainly sought help from r-help instead of calling it a "bug".
Had this hurt anybody's feeling, I express my regret and offer my apologies
to all of them for calling this name.

With best regards,

Dr. A.K. Singh
Head, Department of Agril. Statistics
Indira Gandhi Krishi Vishwavidyalaya, Raipur
Chhattisgarh, India, PIN-492012
Mobile: +919752620740
Email: akhileshsingh.igkv at gmail.com



On Sun, Apr 17, 2016 at 7:52 AM, David Winsemius <dwinsemius at comcast.net>
wrote: