1

I want to find the position of the values that are not zero, for example in row one I want to know how I get 3400 that is in column s8, for the second row I want to find the position of the first element 660, and for the third row I want to know the position of s8 4679. and so on for each row.

        s1      s2      s3      s4      s5      s6       s7      s8      s9     s10     s11
1     0.00    0.00    0.00    0.00    0.00    0.00     0.00 3400.02 3400.02 3400.02 3400.02
2   660.00 1602.44 1202.13 1378.71 1960.37  943.13  1232.44 1107.14  867.43 2966.34  981.11
3     0.00    0.00    0.00    0.00    0.00    0.00     0.00 4679.58 4679.58 4679.58 4679.58
4     0.00    0.00    0.00    0.00    0.00    0.00     0.00    0.00    0.00    0.00    0.00
5     0.00    0.00    0.00    0.00    0.00    0.00     0.00  763.56    0.00    0.00    0.00
6     0.00    0.00    0.00 2000.00 2000.00 2000.00  2000.00 2000.00 2000.00 2000.00 2000.00
7     0.00    0.00    0.00  850.00  850.00 1081.82     0.00    0.00    0.00    0.00    0.00
8     0.00    0.00    0.00 6646.16 6646.16 6646.16  6646.16 6646.16 7562.16 8787.05 6230.86
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • `max_col <- names(df)[max.col(df, ties.method = 'first')]` – Ronak Shah Nov 28 '20 at 02:18
  • i am using this, cont <- function (x) { m<-which(x!=0)[[1]] print(m) } but when I use it to my data frame I get an error, it gives me the result but in the end I get an error and it does not save the result, I do not know if my function may be wrong. – jans castellon Nov 28 '20 at 03:16

0 Answers0