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)