Q:

Function for all rows in a data frame R

I have a question,
I dispose of a data frame:
            MInc      t0.01       t0.1         t0.2       t0.5       t0.8
A4GALT 0.1605681 0.16056814 0.27212265 0.3490585760 0.07486080         NA
AAAS   0.2992754 0.04794018 0.09057540 0.0001127665         NA         NA
AADAC  0.3027883 0.30278830 0.30278830 0.3027883033 0.30278830 0.28501358
AASS   0.1307001 0.12665125 0.12665125 0.1266512501 0.12665125 0.21474030
AATF   0.1453662 0.09392991         NA           NA         NA         NA
AATK   0.2567986 0.11338287 0.11338287 0.1133828663 0.11338287 0.11093412
ABCA8  0.1577148 0.07236169 0.07236169 0.1420553677 0.06185948 0.04529619
ABCB10 0.1437084 0.04794018         NA           NA         NA         NA
ABCB8  0.1022297 0.05264867         NA           NA         NA         NA
ABCC8  0.1577148 0.13209778 0.13209778 0.1320977809 0.07740797         NA
ABCD2  0.1453662 0.26370072 0.23850217 0.0572556220         NA         NA
ABCG2  0.1453662 0.08066152 0.04904863 0.0452961926 0.04529619         NA
ABHD12 0.1062786 0.13495108         NA           NA         NA         NA

I'm searching for a commands for divide the minimum value in each row (omitting the first column) between the corresponding value in the first column for this row. 
The output have to be a data frame with one column containing this value for each row. For example, for the first row of my data, the computation would be this:
A4GALT 0.07486080/0.1605681 = 0.4662246.

Thanks!

A:

We can use pmin to get the minimum value per row.  If you need to divide the 'min' value for each row with all the columns of dataset, we can replicate the the results obtained with pmin.  One option is indexing with row(df1) and divide by 'df1'.
do.call(pmin, c(df1[-1], na.rm=TRUE))[row(df1)]/df1

Or if you need this only for the 1st column, we divide by the subset of 'df1' (with the option drop=FALSE to avoid it getting converted to vector). 
 do.call(pmin, c(df1[-1], na.rm=TRUE))/df1[,1,drop=FALSE] 
 #                 MInc
 #  A4GALT 0.4662246112
 #  AAAS   0.0003767984
 #  AADAC  0.9412965428
 #  AASS   0.9690218294
 #  AATF   0.6461605930
 #  AATK   0.4319888037
 #  ABCA8  0.2872031667
 #  ABCB10 0.3335934434
 #  ABCB8  0.5150036633
 #  ABCC8  0.4908098035
 #  ABCD2  0.3938716290
 #  ABCG2  0.3116005646
 #  ABHD12 1.2697860152

NOTE: I used df1[-1] as the OP mentioned about omitting the first column.  But if the OP assumed omitting the rownames, the code would be
   do.call(pmin, c(df1, na.rm=TRUE))/df1[,1,drop=FALSE] 

Benchmarks
set.seed(238)
m1 <- matrix(rnorm(5000*5000), ncol=5000)
df2 <- as.data.frame(m1)
jalapic <- function() apply(m1[,-1], 1, min, na.rm=TRUE)/m1[,1]
thomas <- function() rowMins(m1[,-1], na.rm=TRUE)/m1[,1]
akrun <- function() do.call(pmin, c(df2[,-1], na.rm=TRUE))/df2[,1]

microbenchmark(jalapic(), thomas(), akrun(), unit='relative', times=20L)
#Unit: relative
#    expr      min       lq     mean   median       uq       max neval cld
#jalapic() 2.255453 2.224805 2.088557 2.145412 2.133398 1.9793887    20   b
#thomas() 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000    20  a 
# akrun() 1.248002 1.227203 1.133792 1.212745 1.174489 0.8228857    20  a 

data
df1 <- structure(list(MInc = c(0.1605681, 0.2992754, 0.3027883, 0.1307001, 
0.1453662, 0.2567986, 0.1577148, 0.1437084, 0.1022297, 0.1577148, 
0.1453662, 0.1453662, 0.1062786), t0.01 = c(0.16056814, 0.04794018, 
0.3027883, 0.12665125, 0.09392991, 0.11338287, 0.07236169, 0.04794018, 
0.05264867, 0.13209778, 0.26370072, 0.08066152, 0.13495108), 
    t0.1 = c(0.27212265, 0.0905754, 0.3027883, 0.12665125, NA, 
    0.11338287, 0.07236169, NA, NA, 0.13209778, 0.23850217, 0.04904863, 
    NA), t0.2 = c(0.349058576, 0.0001127665, 0.3027883033, 0.1266512501, 
    NA, 0.1133828663, 0.1420553677, NA, NA, 0.1320977809, 0.057255622, 
    0.0452961926, NA), t0.5 = c(0.0748608, NA, 0.3027883, 0.12665125, 
    NA, 0.11338287, 0.06185948, NA, NA, 0.07740797, NA, 0.04529619, 
    NA), t0.8 = c(NA, NA, 0.28501358, 0.2147403, NA, 0.11093412, 
    0.04529619, NA, NA, NA, NA, NA, NA)), .Names = c("MInc", 
"t0.01", "t0.1", "t0.2", "t0.5", "t0.8"), class = "data.frame",
 row.names = c("A4GALT", 
"AAAS", "AADAC", "AASS", "AATF", "AATK", "ABCA8", "ABCB10", "ABCB8", 
"ABCC8", "ABCD2", "ABCG2", "ABHD12"))

