如何在更换Bootstrap重采样期间允许R data.frame中的重复行名?

时间:2016-04-16 20:11:19

标签: r twitter-bootstrap

我有3个用于比较的数据框,它们都是通过row.names(基因型,亲属关系,表型)链接的。

为了执行Bootstrap重采样,我想从我的表型文件中取出多个样本并允许替换 - 这需要允许重复的row.names以便所有文件都匹配。

check.rows = Fcheck.names = F都不允许重复。

phenoperm = data.frame(pheno[sample(nrow(pheno), replace = TRUE), ], check.rows = F, check.names = F)

为复制产生更改的row.names:

X1

X1.1

X1.2

当我尝试强制row.names:rownames(phenoperm) <- phenoperm$rownames时出现此错误:

Error in row.names&LT; - data.frame ( TMP , value = value) : duplicate 'row.names' are not allowed In addition: Warning message: non-unique values when setting 'row.names': ‘X1’

非常感谢任何帮助!

更多代码:

for(p in 1:perms) {print(p)

                    ### THE LINE BELOW DOES NOT ALLOW FOR DUPLICATE ROW.NAMES ###
                    ### DUPLICATE ROW.NAMES ARE NECESSARY TO MATCH OTHER FILES ###

                    phenoperm = data.frame(pheno[sample(nrow(pheno), replace = TRUE), ], row.names = phenoperm$row.names, check.names = FALSE, check.rows = FALSE)

                    ### INSTEAD IT PRODUCES DUPLICATE ROW.NAMES AS 23, 23.1, 23.2, ETC ###
                    ### THE NUMBERS IN WHICH A "-.1" OR ".2" ARE ADDED DO NOT MATCH ###


                    result = GRSDbinom.permsfast(data[[chr]], pheno = phenoperm, pheno.col = "pheno.col", addcovar, tx, sanger.dir)
                    top <- max(-log10(result$pv))
                    MAX.LOD = result$POS[which(-log10(result$pv) >= top)]

                    # Save the locus.
                    permutations[p,] = c(min(MAX.LOD), max(MAX.LOD))
            }

0 个答案:

没有答案