在循环转换矩阵到数据帧中使用dplyr后出错

时间:2015-10-01 10:28:36

标签: r

使用dplyr函数后出现此错误。我使用的循环使用矩阵(mymat),然后在另一个步骤中,由于dplyr非常快,我想将该矩阵转换为数据帧(mydf)并运行dplyr函数。所以这就是我所做的:

 loop begins
    #several other function which spit out mymat

        mydf<-as.data.frame(mymat) 
        library(dplyr)
        library(stringi)
          #this is my dplyr function        
          mydata<-data.frame(mydf, check.names = FALSE) %>%
          mutate_each(funs(stri_replace_all(., REF, fixed = "0")), ends_with(".GT")) %>%
          mutate_each(funs(stri_replace_all(., ALT, fixed = "1")), ends_with(".GT")) %>%
          mutate_each(funs(stri_replace_all(., " ", fixed = "/")), ends_with(".GT")) %>%
          mutate_each(funs(stri_replace_all(., "0 0", fixed = "NA")), ends_with(".GT")) %>%
          select(ends_with(".GT")) %>%
          t()

    loop ends

我现在不知道为什么会出现这个错误。还请注意,我需要在前面的步骤中使用矩阵,因此我不能从数据帧开始。

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘select’ for signature ‘"data.frame"’

示例数据在这里:

 mymat<-structure(c("G", "A", "C", "A", "G", "A", "C", "T", "G", "A", 
"1/1", "0/0", "0/0", "NA", "NA", "0,15", "8,0", "8,0", "NA", 
"NA", "1/1", "0/1", "0/0", "NA", "NA", "0,35", "12,12", "15,0", 
"NA", "NA"), .Dim = 5:6, .Dimnames = list(c("chrX:133511988:133511988:G:A:snp", 
"chrX:133528116:133528116:A:C:snp", "chrX:133528186:133528186:C:T:snp", 
"chrX:133560301:133560301:A:G:snp", "chrX:133561242:133561242:G:A:snp"
), c("REF", "ALT", "02688.GT", "02688.AD", "02689.GT", "02689.AD"
)))

0 个答案:

没有答案