lundi 4 mai 2015

Applying if statements to for loops

I am trying to use an if statement within a for loop to compare the values of two columns of a dataframe against each other. A sample of three relevant vectors in my data frame is shown here.

HA
1.2
1.2
1.5
0.547502826
1.7
2.4
1.2846
0.5
0.466394974

HB
11.5,
10.5,
10.95,
0.547502826,
7.6,
6.7,
3.547,
3.85,
3.346972572,

HC
13.75,
11.55,
14.95,
0.547502826,
15.9,
11.05,
5.341,
3.75,
4.545342419,

What I want the loop to do is remove rows where HA and HB have identical numbers. I have tried to do this using this section of code to remove these lines from the dataframe shown here as the object "data".

for(i in rmvalue){
if(as.numeric(rmvalue[i,"HA"])==as.numeric(rmvalue[i,"HB"])){
  data<<-rmvalue[-i,]
} 

R however only appears to evaluate the first expression in the data frame. Not sure how to proceed or if this process can be performed without an if statement as a workaround.

Aucun commentaire:

Enregistrer un commentaire