How to return the 1st row that is 10 percent above the minimum per column in a data frame?

StackOverflow https://stackoverflow.com/questions/20443161

  •  30-08-2022
  •  | 
  •  

Question

Hi I have a data frame and I want to find the 1st value that is 10% above the minimum, and return its row index. This per column.

    H11    H12
1   0.0899 0.0857
2   0.0873 0.0859
3   0.0881 0.0860
4   0.0928 0.0918
5   0.0936 0.0931
6   0.0921 0.0947
7   0.0919 0.0964
8   0.0926 0.0983
9   0.0934 0.1004
10  0.1159 0.2967
11  0.1174 0.3365
12  0.1186 0.3775
13  0.1199 0.4242
14  0.1217 0.4758
15  0.1231 0.5253

The idea is to return something like,

H11    H12
10    8

Sorry i'm not very good at r, I'm not really sure how to tackle this one. Thanks

Était-ce utile?

La solution

Try this, and make sure the result for H12 is correct, I got 6 instead of 8 as the first element above the minimum by 10%

> sapply(df, function(x) which(x > 1.1*min(x))[1])
H11 H12 
 10   6 
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top