I am sure that I am just making a simple mistake.
I have a large matrix 3307592x9 that I need to iterate through and if column 8 (char/string) == 9 (char/string) (case insensitive) then column 3-7 (numeric 0-1) need to be 1-self. The code that I have written is:
for (i in 1:3307592){
if(grepl(chr2SnpFreqNorm[i,8], chr2SnpFreqNorm[i,9], ignore.case=TRUE)){
chr2SnpFreqNorm[i,3] <- 1 - chr2SnpFreqNorm[i,3]
chr2SnpFreqNorm[i,4] <- 1 - chr2SnpFreqNorm[i,4]
chr2SnpFreqNorm[i,5] <- 1 - chr2SnpFreqNorm[i,5]
chr2SnpFreqNorm[i,6] <- 1 - chr2SnpFreqNorm[i,6]
chr2SnpFreqNorm[i,7] <- 1 - chr2SnpFreqNorm[i,7]
}
}
When I attempt to execute my R client just hangs for over half an hour before I cancel the command. I'm not sure what I have done wrong as the code looks correct to me.
/edit Example data
> chr2SnpFreqNorm[1:10,]
ID pos ceuChr2SnpFreq chsChr2SnpFreq lwkChr2SnpFreq
1 rs187078949 10133 0.070588235 0.000 0.030927835
2 rs191522553 10140 0.005882353 0.000 0.005154639
3 rs149483862 10286 0.100000000 0.135 0.226804124
4 rs150919307 10297 0.147058824 0.070 0.113402062
5 rs186644623 10315 0.000000000 0.000 0.000000000
6 rs193294418 10345 0.017647059 0.000 0.036082474
7 rs185496709 10386 0.082352941 0.020 0.087628866
8 rs188771313 10419 0.229411765 0.085 0.056701031
9 rs192945962 10425 0.100000000 0.020 0.015463918
10 rs184397180 10431 0.064705882 0.005 0.036082474
tsiChr2SnpFreq yriChr2SnpFreq ALT AA
1 0.035714286 0.045454545 A a
2 0.005102041 0.005681818 A C
3 0.239795918 0.170454545 A t
4 0.168367347 0.130681818 T t
5 0.000000000 0.005681818 G C
6 0.030612245 0.028409091 A G
7 0.035714286 0.113636364 T t
8 0.147959184 0.090909091 G G
9 0.091836735 0.034090909 G c
10 0.015306122 0.045454545 T a
>