I have a matrix with a column of different genes and a corresponding column of the -log(P-values)
for each possible SNP for every gene.
So the matrix has 3 columns: Gene_lable
, SNP and minus_logpval
. I'm trying to write a code that identifies the SNP with the highest -log(P-value)
for each gene. Here's the head(data):
SNP Gene_label minus_logpval
1 rs3934834 HES4/ENSG00000188290 14.1031
2 rs3766193 HES4/ENSG00000188290 7.0203
3 rs3766192 HES4/ENSG00000188290 10.7420
4 rs3766191 HES4/ENSG00000188290 10.4323
5 rs9442371 HES4/ENSG00000188290 10.2941
6 rs9442372 HES4/ENSG00000188290 8.4235
This is the start of the code:
for(i in 1:254360) {
max_pval = 0
if(data$Gene_label[i]==data$Gene_label[i+1]) {
x = array(NA, dim=c(0,2));
x[i] = data$minus_logpval[i];
x[i+1] = data$minus_logpval[i+1];
temp = max(x);
if (temp>max_pval) {
max_pval=temp
line = i
}
But for some reason, R keeps giving me the error: Error in is.ordered(x) : argument "x" is missing, with no default.
I didn't even use the is-ordered(x) function... I think the error's in the way I initialized x (which should be an array) but I don't know how to fix it.