mercredi 30 septembre 2015

Determine the max values in one column based in another column

I would like to determine the max the values in column value1 based the values in column value2:

df <- 'inf value1 value2
       xx1   20    30
       xx2   15    40
       xx3   25    20'
df <- read.table(text=df, header=T)

My expected output would be like that:

out <- 'inf value1 value2
       xx1   20    30
       xx2   15    40
       xx3   20    20'
out <- read.table(text=out, header=T)

In the third row in the column value2 now I have 20 instead 25, because this is the value at value2column at the same row. I have a large dataset, I would appreciate any ideas to deal with that. Thank you!

Aucun commentaire:

Enregistrer un commentaire