Re: [R] delete data row

2010-10-18 Thread William Dunlap
> To: David Winsemius > Cc: William Dunlap; R-help@r-project.org > Subject: Re: [R] delete data row > > I used the -which() construct initially to try to show "deleting" > cases. I believe it hung around longer than it should have. That > said, I have also had David&#

Re: [R] delete data row

2010-10-17 Thread Joshua Wiley
I used the -which() construct initially to try to show "deleting" cases. I believe it hung around longer than it should have. That said, I have also had David's experience with NAs. What about a vectorized version of identical(TRUE, x)? This avoids the which() problem Bill pointed out, and the

Re: [R] delete data row

2010-10-17 Thread David Winsemius
On Oct 17, 2010, at 3:56 PM, William Dunlap wrote: I had been thinking of: x <- c(1, (2^(0.5))^2 , 3, 5, (2^(0.5))^2 , 3, 1) y <- 2 x[-which(zapsmall(x-y) == 0)] [1] 1 3 5 3 1 Using which() to convert logicals into integer subscripts is almost always unnecessary and often wrong. At one

Re: [R] delete data row

2010-10-17 Thread William Dunlap
> I had been thinking of: > > x <- c(1, (2^(0.5))^2 , 3, 5, (2^(0.5))^2 , 3, 1) > > y <- 2 > > x[-which(zapsmall(x-y) == 0)] > [1] 1 3 5 3 1 Using which() to convert logicals into integer subscripts is almost always unnecessary and often wrong. In this case it fails when no x is close to y, be

Re: [R] delete data row

2010-10-16 Thread David Winsemius
On Oct 16, 2010, at 5:45 PM, Joshua Wiley wrote: Jim and David, I certainly agree with your suggestions. How would you implement all.equal()? Since it compares entire objects (and the OP's goal is to remove any rows that equal some value), the only option I saw was to use *apply or a loop.

Re: [R] delete data row

2010-10-16 Thread Joshua Wiley
Jim and David, I certainly agree with your suggestions. How would you implement all.equal()? Since it compares entire objects (and the OP's goal is to remove any rows that equal some value), the only option I saw was to use *apply or a loop. zapsmall() is easier, (though it seems potentially sl

Re: [R] delete data row

2010-10-16 Thread David Winsemius
IRD; There is a danger in applying logical tests of equality to floating point numbers. It may be safer to use all.equal or zapsmall in the construction of your tests. > all.equal( (2^(0.5))^2 , 2) [1] TRUE > (2^(0.5))^2 == 2 [1] FALSE -- David. On Oct 16, 2010, at 1:30 PM, Joshua Wiley

Re: [R] delete data row

2010-10-16 Thread jim holtman
It is best to use 'all.equal' keeping in mind FAQ 7.31. On Sat, Oct 16, 2010 at 1:30 PM, Joshua Wiley wrote: > Dear IRD, > > One way is to select every row except those where y = y.j and then > assign that to IR.  In my example, which() returns a vector of the row > numbers where the condition ev

Re: [R] delete data row

2010-10-16 Thread Joshua Wiley
Dear IRD, One way is to select every row except those where y = y.j and then assign that to IR. In my example, which() returns a vector of the row numbers where the condition evaluated TRUE, then I used `-` to select not those rows. IR <- IR[-which(IR$y == y.j), ] HTH, Josh On Sat, Oct 16, 20

[R] delete data row

2010-10-16 Thread IRD
Dear All I have data like this: > IR xy [1,] 5 2.865490 [2,] 3 1.454611 [3,] 3 2.258772 [4,] 6 1.476128 [5,] 4 2.771606 > y.j y 2.865490 > and I want to delete data row in IR where y = y.j How I can do. IRD __ R-help@r-project.org