我确信我只是犯了一个简单的错误。
我有一个需要迭代的大矩阵 3307592x9,如果第 8 列(字符/字符串)== 9(字符/字符串)(不区分大小写),则第 3-7 列(数字 0-1)需要为 1-self . 我写的代码是:
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]
}
}
当我尝试执行我的 R 客户端时,我会在取消命令之前挂起半个多小时。我不确定我做错了什么,因为代码对我来说是正确的。
/edit 示例数据
> 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
>