Re: [R] ignoring zeros or converting to NA

2008-08-14 Thread Thomas Lumley
done at infinite precision, then x==0 may not work. -thomas --- On Thu, 14/8/08, Roland Rau [EMAIL PROTECTED] wrote: From: Roland Rau [EMAIL PROTECTED] Subject: Re: [R] ignoring zeros or converting to NA To: rcoder [EMAIL PROTECTED] Cc: r-help@r-project.org Received: Thursday, 14

Re: [R] ignoring zeros or converting to NA

2008-08-14 Thread markleeds
Hi: If I remember correctly, I think I gave you something like mat[mat == 0]-NA. I think what you're doing below is pretty different from that but I may not be understanding what you want ? Let me know if I can clarify more because my intention was not to guide you into doing below. Looping is

Re: [R] ignoring zeros or converting to NA

2008-08-14 Thread Daniel Malter
Sorry for jumping in. I haven't read the entire conversation. But imagine you want to compute 1/x for the entire matrix and your matrix has 0s and NAs. Then you could do: ##define function f-function(x){1/x} ##sample data y=c(0,1,2,3,4,5,6,7,NA) ##arrange in matrix mat=matrix(y,3,3)

Re: [R] ignoring zeros or converting to NA

2008-08-14 Thread Bert Gunter
: Thursday, August 14, 2008 1:46 PM To: r-help@r-project.org Subject: Re: [R] ignoring zeros or converting to NA Sorry for jumping in. I haven't read the entire conversation. But imagine you want to compute 1/x for the entire matrix and your matrix has 0s and NAs. Then you could do: ##define

Re: [R] ignoring zeros or converting to NA

2008-08-13 Thread Roland Rau
Hi, since many suggestions are following the form of x[x==0] (or similar) I would like to ask if this is really recommended? What I have learned (the hard way) is that one should not test for equality of floating point numbers (which is the default for R's numeric values, right?) since the

Re: [R] ignoring zeros or converting to NA

2008-08-13 Thread Thomas Lumley
Integers (up to a fairly high limit) are represented exactly, as are fractions whose denominator is a power of two (again up to a fairly high limit), so x==0 is fine in that sense. If x is computed by floating point operations you do have to worry whether these are exact, eg, with

Re: [R] ignoring zeros or converting to NA

2008-08-13 Thread S Ellison
The help page on binary operators (see ?==) confirms that binary representation of fractional representation is not catered for and points to all.equal as a more suitable test method for those cases. Steve E Thomas Lumley [EMAIL PROTECTED] 13/08/2008 16:47 Integers (up to a fairly high limit)

Re: [R] ignoring zeros or converting to NA

2008-08-13 Thread Henrik Bengtsson
FYI, there is an isZero() in the R.utils package that allows you to specify the precision. It looks like this: isZero - function (x, neps=1, eps=.Machine$double.eps, ...) { (abs(x) neps*eps); } /Henrik On Wed, Aug 13, 2008 at 8:23 AM, Roland Rau [EMAIL PROTECTED] wrote: Hi, since many

Re: [R] ignoring zeros or converting to NA

2008-08-13 Thread rcoder
Thank you for all your replies. Borrowing an alternative solution kindly provided by Mark Leeds, I am using a conditional statement to pass non-zero values to a holding matrix that has cells initially set to NA. The code is as follows: ##Code Start mat_zeroless-matrix(NA,5000,2000)

Re: [R] ignoring zeros or converting to NA

2008-08-13 Thread Moshe Olshansky
] ignoring zeros or converting to NA To: rcoder [EMAIL PROTECTED] Cc: r-help@r-project.org Received: Thursday, 14 August, 2008, 1:23 AM Hi, since many suggestions are following the form of x[x==0] (or similar) I would like to ask if this is really recommended? What I have learned (the hard

[R] ignoring zeros or converting to NA

2008-08-12 Thread rcoder
Hi everyone, I have a matrix that has a combination of zeros and NAs. When I perform certain calculations on the matrix, the zeros generate Inf values. Is there a way to either convert the zeros in the matrix to NAs, or only perform the calculations if not zero (i.e. like using something similar

Re: [R] ignoring zeros or converting to NA

2008-08-12 Thread stephen sefick
when you read it in na.string=0 On Tue, Aug 12, 2008 at 1:43 PM, rcoder [EMAIL PROTECTED] wrote: Hi everyone, I have a matrix that has a combination of zeros and NAs. When I perform certain calculations on the matrix, the zeros generate Inf values. Is there a way to either convert the zeros

Re: [R] ignoring zeros or converting to NA

2008-08-12 Thread Mike Prager
rcoder [EMAIL PROTECTED] wrote: I have a matrix that has a combination of zeros and NAs. When I perform certain calculations on the matrix, the zeros generate Inf values. Is there a way to either convert the zeros in the matrix to NAs, or only perform the calculations if not zero (i.e. like

Re: [R] ignoring zeros or converting to NA

2008-08-12 Thread Charles C. Berry
On Tue, 12 Aug 2008, Mike Prager wrote: rcoder [EMAIL PROTECTED] wrote: I have a matrix that has a combination of zeros and NAs. When I perform certain calculations on the matrix, the zeros generate Inf values. Is there a way to either convert the zeros in the matrix to NAs, or only perform

Re: [R] ignoring zeros or converting to NA

2008-08-12 Thread stephen sefick
I have been reading this thread and I am having a hard interpreting what these mean. I know that the result is that all of the values that are zero in a are replaced by NA. Let me try and write it out is.na(a[a==0] ) - TRUE you pull out of a all of the times that are equal to zero then is.na

Re: [R] ignoring zeros or converting to NA

2008-08-12 Thread Steven McKinney
zeros or converting to NA I have been reading this thread and I am having a hard interpreting what these mean. I know that the result is that all of the values that are zero in a are replaced by NA. Let me try and write it out is.na(a[a==0] ) - TRUE you pull out of a all of the times

Re: [R] ignoring zeros or converting to NA

2008-08-12 Thread Charles C. Berry
On Tue, 12 Aug 2008, stephen sefick wrote: I have been reading this thread and I am having a hard interpreting what these mean. I know that the result is that all of the values that are zero in a are replaced by NA. Let me try and write it out is.na(a[a==0] ) - TRUE you pull out of a all of