I am getting this error after I use a dplyr function. The loop I have uses matrix (mymat
), and then in another step, since dplyr is extremely fast, I want to convert that matrix to dataframe (mydf
) and run dplyr function. So this is what I did:
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
I don't now why I get this error. Please also note that I need to work with matrix in preceding steps and therefore I can't start with the dataframe.
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘select’ for signature ‘"data.frame"’
The sample data is here:
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"
)))