Using functions how would I go about do this question? (I already have a mean defined for a function of x.) Write a function called MyMean2. This function has two arguments, x and nonzero, where nonzero has the default value TRUE. This function should return the (Previous defined mean of x) if nonzero=FALSE (Previous defined mean of x) for all x's>0 if nonzero=TRUE Much appreciated. elliot.welch at virgin.net Sent from my BlackBerry? smartphone
Finding the mean.
3 messages · elliot.welch at virgin.net, jim holtman, PIKAL Petr
if (nonzero) mean(x[x>0]) else mean(x)
On Sat, Mar 10, 2012 at 2:47 PM, <elliot.welch at virgin.net> wrote:
Using functions how would I go about do this question? (I already have a mean defined for a function of x.) Write a function called MyMean2. This function has two arguments, x and nonzero, where nonzero has the default value TRUE. This function should return the (Previous defined mean of x) if nonzero=FALSE (Previous defined mean of x) for all x's>0 if nonzero=TRUE Much appreciated. elliot.welch at virgin.net Sent from my BlackBerry? smartphone
______________________________________________ R-help at 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.
Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
1 day later
Hi
Using functions how would I go about do this question? (I already have a mean defined for a function of x.) Write a function called MyMean2. This function has two arguments, x and nonzero, where nonzero has the default value TRUE. This function should
return the
(Previous defined mean of x) if nonzero=FALSE (Previous defined mean of x) for all x's>0 if nonzero=TRUE
You already have got an answer but it would be probably better to change zeroes to NA values and use mean(something, na.rm=T) If the zeroes have meaning you can leave them, if they represent NA change them to NA. It seems to me better approach. Regards Petr
Much appreciated. elliot.welch at virgin.net Sent from my BlackBerry? smartphone
______________________________________________ R-help at 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.