[R] deleting rows provisionally

onyourmark william108 at gmail.com
Fri Apr 24 13:50:48 CEST 2009


Hi. Thanks very much for the reply and the good suggestion. It works well.
But I don't get why the for loop is not deleting anything or making any
assignments? Or I should say, doesn't answer3[-i,] delete entries from
answer3 when the if condition is true?
Also, in your first solution 
answer2[-(answer2[,1]==answer2[,2]),]   

can I say that you are indexing answer2 by answer2[,] and all of the
deletion is coming in the first argument and specifically you are deleting
every entry in answer2 where the first elements of the first and second
columns are the same.
So for example, 
if I wanted instead to switch the elements of the first and second column
whenever they are different what would I do? confused.

Ben Bolker wrote:
> 
> 
> 
> onyourmark wrote:
>> 
>> I have an object. I think it is a matrix, called 'answer2'
>>  str(answer2)
>>  int [1:1537, 1:2] 1 399 653 2 3 600 4 5 271 870 ...
>>  - attr(*, "dimnames")=List of 2
>>   ..$ : chr [1:1537] "a4.1" "hirschsprung.399" "peritoneal.653"
>> "abdomen.2" ...
>>   ..$ : chr [1:2] "row" "col"
>> 
>> 
>> I want to delete rows that have the same entries.
>> 
>> 
> 
> Your "for" loop didn't make any assignments.
> How about 
> 
> answer3 <- answer2[-(answer2[,1]==answer2[,2]),]  
> 
> or
> 
> answer3 <- answer2[answer2[,1]!=answer2[,2],]  
> 
> (which will be much faster than a loop anyway)
> 
> ?
> 

-- 
View this message in context: http://www.nabble.com/deleting-rows-provisionally-tp23209365p23214891.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list