1

hoping for a bit of help with something that should (hopefully) be easy enough for those with the knowledge.

I am working with a dataset with 111 columns and 300 rows. The first 70 columns are control data, columns 71-111 contain data on people with diabetes. I have performed the following t-test on the first row:

row1 <- data[1:1,]

control_cols <- c(1:70)
control <- row1[control_cols]

diabetes_cols <- c(71:111)
diabetes <- row1[diabetes_cols]

t.test(control, diabetes, mu=0, paired = F, conf.level=0.95)

Is there a way than I can use the apply function to automate this to perform the t-test on each row, so that I can see the p-values of each row individually?

billroggio
  • 27
  • 3

1 Answers1

1

You can use apply to execute the t-test for each row, and assign the result to a new column in data

data["pvalue"] = apply(data,1,function(r) t.test(r[1:70], r[71:111])$p.value)
langtang
  • 22,248
  • 1
  • 12
  • 27