我的数据在R控制台中如下所示:
dim(df1)
marker X1 X73 X88 X9 X17 X25 X33 X41 X49
1 1228104|F|0-8:C>T-8:C>T 0 0 0 0 0 NA 0 0 0
2 2277607|F|0-10:A>T-10:A>T NA 0 0 NA NA NA NA 0 0
3 100023173|F|0-47:G>A-47:G>A 0 0 0 NA NA NA 0 0 0
4 1043336|F|0-7:A>G-7:A>G 1 1 1 0 NA 0 1 1 1
5 1212218|F|0-49:A>G-49:A>G 0 0 0 0 0 0 0 0 0
6 1019554|F|0-14:T>C-14:T>C 0 0 0 0 NA 0 0 0 0
7 1114675|F|0-18:T>C-18:T>C 0 0 0 0 0 0 0 0 0
8 100024550|F|0-16:G>A-16:G>A NA NA NA NA NA NA 0 0 0
9 1271969|F|0-22:T>A-22:T>A 0 0 NA 0 NA NA 0 0 0
10 1106702|F|0-8:C>A-8:C>A 0 NA 0 0 0 0 0 0 NA
df1 [1:10,1:10]
## % of missing per genotypes/samples
pmg <- apply(df1, 2, function(gid) sum(is.na(gid)) / length(gid))
length(pmg)
## dropping bad genotypes/ samples
df2 <- data.frame(marker=df1[,1], df1[,pmg <= .2][,-1])
dim(df2)
#[1] 54003 909
## % of missing per snp
pms <- apply(df1[pmg <= .2, ], 1,
function(snp) sum(is.na(snp)) / length(snp))
hist(pms)
length(pms)
# removing bad snps with high missing values
df3 <- df2[pms <=0.2,]
dim(df3)
# [1] 37982 909
我根据此(FILTER1)过滤数据
## % of missing per snp
pms <- apply(df1[pmg <= .2, ], 1,
function(snp) sum(is.na(snp)) / length(snp))
hist(pms)
length(pms)
# removing bad snps with high missing values
df2 <- df1[pms <=0.2,]
dim(df2)
## % of missing per genotypes/samples
pmg <- apply(df1, 2, function(gid) sum(is.na(gid)) / length(gid))
length(pmg)
## dropping bad genotypes/ samples
df3 <- data.frame(marker=df2[,1], df2[,pmg <= .2][,-1])
dim(df3)
我尝试运行相同的过滤器,但是这次我按照以下步骤切换了两个步骤的顺序(过滤器2):
> pms <- apply(df1[pmg <= .2, ], 1,
> function(snp) sum(is.na(snp)) / length(snp))
当我在FILTER 2中运行此代码时;
[.data.frame
它给了我这个错误:
protractor.Key.COMMAND
(df1,pmg <= 0.2,)中出现错误:找不到对象'pmg'
如您所见,我切换了几个步骤,因此也应该修改代码才能正常工作。但是我不知道怎么做。
答案 0 :(得分:1)
使用前,您需要定义pmg
。
只需将本节移到您的代码顶部即可:
## % of missing per genotypes/samples
pmg <- apply(df1, 2, function(gid) sum(is.na(gid)) / length(gid))
length(pmg)