An example with made up RNAseq data.frame
please please see the guide i shared on reprex for how to do this yourself in the future. I spent time making mock data to demo for you when really you should have provided it
I would use purrr to handle the iteration and result collation, and tryCatch to handle error cases
RNAseq <- structure(list(
somevalue = c( 20.22, 15.84, 20, 22.9, 18.3, 18.9, 17.4, 17.6, 18, 17.98, 17.82),
a = c( 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0),
b = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
c = c( 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3),
d = c( 1, 4, 2, 2, 4, 4, 3, 3, 3, 4, 4)),
row.names = c(NA, -11L), class = "data.frame")
#amounts to a t test of c(1,0) with c(3,1)
t.test(RNAseq[1, 2:3], RNAseq[1, 4:5])$p.value
#[1] 0.3498856
#but do a t test of c(0,0) with c(3,3) would error as follows
t.test(RNAseq[7, 2:3], RNAseq[7, 4:5])$p.value
#Error in t.test.default(RNAseq[7, 2:3], RNAseq[7, 4:5]) :
# data are essentially constant
#therefore wrap the ttest in a trycatch that handles the error by making the result NA_real_
library(purrr)
gathered_p_vals <- map_dbl( 1:nrow(RNAseq),
~ tryCatch(t.test(RNAseq[.x, 2:3],
RNAseq[.x, 4:5])$p.value,
error = function(c) NA_real_))