0

So i have this table with the results like this:

         V2         V3       V4         V5         V6        V7   
1  14.06863   11.50424 333173.1        0.0    0.00000       
2  14.50265   11.89501 387709.7    54536.6    0.43402 125654.58   
3  14.55234   11.95746 402124.0    14414.3    0.04969 290084.52  
4  14.78606   12.14149 453059.3    50935.3    0.23372 217933.00   
5  15.16970   12.51004 496142.1    43082.8    0.38364 112300.07   
6  14.41104   11.81296 539661.3    43519.2   -0.75866 -57363.25 
7  14.86976   12.23968 603475.4    63814.1    0.45872 139113.40

The dataframe is called d and what i need is to add a new column called Best and add'best' in the row that has negative V6 and positive V5

How to add this row? Thanks!

Dea12
  • 55
  • 1
  • 2
  • 7

1 Answers1

0

To add Best column:

d$Best <- ""
d$Best[which(with(d, Delta_Cost>0 & Delta_LY<0))] <- "best"
redmode
  • 4,821
  • 1
  • 25
  • 30
  • Thank you very much!!!! This was all i needed :) One question, how can i create another dataframe now, if i remove the row that has best on it? I just remove the 6th row now (based on my example) – Dea12 Feb 20 '14 at 10:09
  • `d <- d[-which(d$Best=="best"),]` removes from `d` all rows with `Best` column equal to "best" – redmode Feb 20 '14 at 10:11