Skip to content
Prev 175932 / 398506 Next

Deleting rows based on identity variable

On 3/04/2009, at 9:30 AM, gina patel wrote:

            
Others have told you how to do what you want.  It would be useful
for you to understand why what you ***did*** didn't work.

Note that ``id==4'' yields a *logical* vector with entries TRUE and  
FALSE.

When an arithmetic operator is applied, as in -(id==4) [NOTE: THE ``c 
()'' wrapper
is TOTALLY UNNECESSARY HERE.] the vector is coerced to a numeric  
vector of
-1's (for TRUE) and 0's (for FALSE).  Thus you are asking d2 to be d1 
[i,] where
i is a vector of -1's and 0's.  The -1's say to throw away the ``1- 
th'' (first)
row of d1; the 0's say to pick out the 0-th row of d1 (and there is  
no 0-th row
so this doesn't do anything).  Thus you are in effect asking for d1 
[2:25,].

And that's what you get.  Look carefully --- it is not correct to say  
that when
you looked at d2 *no* data were removed; d2 is equal to d1 with its  
first row
removed.  I.e. your operation didn't remove what you wanted, but it  
removed
*something*.

	cheers,

		Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}