Re: [R] FW: NaN from function

2012-02-23 Thread Petr Savicky
On Thu, Feb 23, 2012 at 04:40:07PM -, Ted Harding wrote: [...] > A basic solution for this special case would be > > zt=function(x){ > if (sd(x) == 0) return(0*x) else return( (x-mean(x))/sd(x) ) > } > > This should cover the case where length(table(x))==1 (see also below). > > I'm n

Re: [R] FW: NaN from function

2012-02-23 Thread Ted Harding
On 23-Feb-2012 Jonathan Williams wrote: > Dear Helpers, > I wrote a simple function to standardise variables if they > contain more than one value. If the elements of the variable > are all identical, then I want the function to return zero. > > When I submit variables whose elements are all ident

[R] FW: NaN from function

2012-02-23 Thread Jonathan Williams
Dear Helpers, I wrote a simple function to standardise variables if they contain more than one value. If the elements of the variable are all identical, then I want the function to return zero. When I submit variables whose elements are all identical to the function, it returns not zero, but