0

I'm doing about 10,000 individual chi-square tests in R using a for loop. The tests themselves seem to be running fine, but I'm having trouble extracting the p-values. Ideally I'd like to get the p-values into a pre-existing dataframe. (I've also tried using the Magic For package but (I presume) because of how the chi-square test results are output, the entire output is in one column, which still isn't really what I want.)

This is what I have so far.

Pat1results<-data.frame(Markers=Pat1_markers,p=NA) #dataframe I want the p-values to end up in

test<-for (i in 1:nrow(Pat1_obs)){
  print(i)
  ChiSq<-chisq.test(c(Pat1_obs[i,1],Pat1_obs[i,2]),
                          correct=FALSE,
                          p=AllHetHomoexpected)$p.value
  Pat1results[i,"p"]<-ChiSq
}

However, the column that should hold the p-values is all NAs. How do I get the p-values in there?

(Apologies if this should be really obvious--I'm still getting acquainted with R)

eLee
  • 1
  • 1
  • 2
    Hello @eLee it would be great if we could have some reproducible example. See this topic: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Brutalroot Oct 26 '20 at 18:53
  • It turns out the problem was in the other column of the results dataframe, the contents of which were being pulled (apparently incorrectly) from another dataframe. Next time I'll make the reproducible example before I post a question--lesson learned. – eLee Oct 27 '20 at 02:04

0 Answers0