Carlos Morales
2009-Feb-22 10:20 UTC
[R] Error in var(x, na.rm = na.rm) : no complete element pairs
Hello all, I'm trying to calculate the standar desviation and I'm using the function sd(x,na.rm=TRUE) and I have this error:? Error in var(x, na.rm = na.rm) : no complete element pairs . Why happen this?, What can I do to solve it?. x is list of three numbers which I have from a table. Thanks so much from Spain Carlos Morales Diego
Carlos Morales
2009-Feb-22 11:11 UTC
[R] Error in var(x, na.rm = na.rm) : no complete element pairs
Hello all, I'm trying to calculate the standar desviation with sd(x,na.rm=TRUE) and I don't know why I have this error Error in var(x, na.rm = na.rm) : no complete element pairs when I try to calculate it, I have been looking for information about this error but nothing. Why it happens?. What can I do to fix it?. Thanks so much from Spain Carlos Morales Diego
Carlos Morales
2009-Mar-05 11:21 UTC
[R] Error in var(x, na.rm = na.rm) : no complete element pairs
Hello, I still have the same error which I have written in the Subject field, I leave here the code and I hope you can help me with this: filter.clones<-function(zz.info,crom.info) { clones.info<-zz.info cat("Removing clones which has a flag minor than 0\n") ord <- order(clones.info$Flags) clones.info<- clones.info[ ord, ] #for(j in 1:nrow(clones.info)) #{ del<-0 #print(j) del<-which(as.numeric(clones.info$Flags)<0) if (length(del)!=0) { #print(j) clones.info<-clones.info[-del,] #eliminados.info<-clones.info[del,] #if(j==1) #{ # j<-0 #} } #} ##Eliminar levaduras, moscas etc #for(j in 1:nrow(clones.info)) #{ del1<-0 del1<-grep("mix",clones.info$Name) if (length(del1)!=0) { # print(j) clones.info<-clones.info[-del1,] } #} #for(j in 1:nrow(clones.info)) #{ del2<-0 del2<-grep("fly",clones.info$Name) if (length(del2)!=0) { # print(j) clones.info<-clones.info[-del2,] } #} #for(j in 1:nrow(clones.info)) #{ del3<-0 del3<-grep("pombe",clones.info$Name) if (length(del3)!=0) { # print(j) clones.info<-clones.info[-del3,] } #} #for(j in 1:nrow(clones.info)) #{ del4<-0 del4<-grep("DMSO",clones.info$Name) if (length(del4)!=0) { # print(j) clones.info<-clones.info[-del4,] } #} #Eliminar los clones que estan unidos por un + o un menos #for(j in 1:nrow(clones.info)) #{ del5<-0 del5<-grep("[+]",clones.info$Name) if (length(del5)!=0) { # print(j) clones.info<-clones.info[-del5,] } #} #for(j in 1:nrow(clones.info)) #{ del6<-0 del6<-grep("[-]",clones.info$Name) if(length(del6)!=0) { # print(j) clones.info<-clones.info[-del6,] } #} #for(j in 1:nrow(clones.info)) #{ del7<-0 del7<-grep("rep",clones.info$Name) if(length(del7)!=0) { # print(j) clones.info<-clones.info[-del7,] } #} del8<-0 del8<-grep("REP",clones.info$Name) if(length(del8)!=0) { # print(j) clones.info<-clones.info[-del8,] } #cat("Numero de clones:",NROW(clones.info$Name),"\n") #chroms.info<-croms.info(PruebaDefinitiva.obj) #cat("Reordering the chromosomes\n") #ord <- order(chroms.info$picked_off_as_SI_name) #chroms.info<- chroms.info[ ord, ] #ord <- order(PruebaDefinitiva.obj$crom.info$picked_off_as_SI_name) ##crom.info <- crom.info[ ord, ] nrow(clones.info) #a<-PruebaDefinitiva.obj$zz.info #PruebaDefinitiva.obj$zz.info<-0 #PruebaDefinitiva.obj$zz.info<-clones.info #PruebaDefinitiva.obj$zz.info clones.info cat("Reordering the chromosomes\n") ord <- order(crom.info$picked_off_as_SI_name) crom.info<- crom.info[ ord, ] #arch.info<-cbind(arch.info,000) #names(arch.info)[NCOL(arch.info)]<-"Cromosomas" clones2.info<-clones.info clones2.info<-cbind(clones2.info,000) names(clones2.info)[NCOL(clones2.info)]<-"Cromosomas" clones2.info ##A?adir columna con los cromosomas #ncol(arch.info) #arch.info<-arch.info #arch.info<-cbind(arch.info,000) #names(arch.info)[NCOL(arch.info)]<-"Cromosomas" ord <- order(clones2.info$Name) clones2.info<- clones2.info[ ord, ] for(i in 1:nrow(clones2.info)) { cat("Processing clon ",i,"\n") find<-match(clones2.info$Name[i],crom.info$picked_off_as_SI_name,nomatch=0) print(find) if((length(find)!=0) &&(find!=0)) { clones2.info$Cromosomas[i]<-paste(crom.info$current_chromosome[find]) } find<-0 } del1<-0 del1<-grep("X",clones2.info$Cromosomas) if (length(del1)!=0) { # print(j) clones2.info<-clones2.info[-del1,] } del1<-0 del1<-grep("Y",clones2.info$Cromosomas) if (length(del1)!=0) { # print(j) clones2.info<-clones2.info[-del1,] } del1<-0 del1<-grep("Un_",clones2.info$Cromosomas) if (length(del1)!=0) { # print(j) clones2.info<-clones2.info[-del1,] } del1<-0 del1<-grep("DR",clones2.info$Cromosomas) if (length(del1)!=0) { # print(j) clones2.info<-clones2.info[-del1,] } ord <- order(clones2.info$Cromosomas) clones2.info<- clones2.info[ ord, ] count<-0 for(j in 1:nrow(clones2.info)) { nchar(clones2.info$Cromosomas[j]) if(nchar(clones2.info$Cromosomas[j])==0) { count<-count+1 #b<-j #arch2.info<-arch2.info[-j,] } #j<-b } for(j in (count+1):nrow(clones2.info)) { clones2.info[j-count,]<-clones2.info[j,] } del<-0 del<-which(clones2.info$Cromosomas==0) if (length(del)!=0) { #print(j) clones2.info<-clones2.info[-del,] #if(j==1) #{ # j<-0 #} } #for(j in 1:nrow(arch2.info)) #{ # del<-0 # del<-pmatch("0",arch2.info$Cromosomas[j]) # if((del!=0)&&(length(del)!=0)) # { # a<-j # arch2.info<-arch2.info[-del,] # } # j<-a #} clones2.info tablesnew.info<-clones2.info Log<-paste(tablesnew.info[,70]) Log cat("Hola holita\n") x<-median(as.numeric(Log),na.rm=TRUE) tablesnew.info<-cbind(tablesnew.info,0) cat("Hola holita\n") names(tablesnew.info)[NCOL(tablesnew.info)]<-"LogminusMediana" for(i in 1:nrow(tablesnew.info)) { tablesnew.info$LogminusMediana[i]<-as.numeric(as.character(Log[i]))-x } finder<-grep(-x,tablesnew.info$LogminusMediana) tablesnew.info$LogminusMediana[finder]<-as.character(NA) tablesnew.info triplicadclones.info<-data.frame(paste(tablesnew.info$Name)) names(triplicadclones.info)[1]<-"Name" tripliclones.info<-data.frame(paste(levels(triplicadclones.info$Name))) names(tripliclones.info)[1]<-"Name" tripliclones.info<-cbind(tripliclones.info,000) names(tripliclones.info)[2]<-"LogminusMediana1" tripliclones.info<-cbind(tripliclones.info,000) names(tripliclones.info)[3]<-"LogminusMediana2" tripliclones.info<-cbind(tripliclones.info,000) names(tripliclones.info)[4]<-"LogminusMediana3" cat("Donde co?os esta el error\n") i<-1 s<-1 del<-0 for(i in 1:nrow(tripliclones.info)) { cat(i) d<-tripliclones.info$Name[i] del<-grep(d,tablesnew.info$Name) #print(del) #print(nrow(del)) for(c in 1:NROW(del)) { tripliclones.info[i,c+1]<-tablesnew.info$LogminusMediana[del[c]] } } cat("Estoy aqui") del<-grep("V",names(tripliclones.info)) if(length(del)!=0) { tripliclones.info<-tripliclones.info[,-del] } cat("Y aqui") tripliclones.info j<-0 c<-0 d<-0 eliminados<-0 for(i in 1:NROW(tripliclones.info)) { for(j in 2:4) { if(is.na(tripliclones.info[i,j])) { c<-c+1 } } if(c>=2) { d<-d+1 eliminados[d]<-i #gain.info<-gain.info[-i,] c<-0 } c<-0 } cat("Hola intentando arreglar") tripliclones.info<-cbind(tripliclones.info,000) names(tripliclones.info)[5]<-"Estandar_desviation" for(i in 1:NROW(tripliclones.info)) { de<-0 s[1]<-0 s[2]<-0 s[3]<-0 sumatorio<-0 for(c in 1:3) { s[c]<-as.numeric(tripliclones.info[i,c+1]) } cat(s) cat(i) de<-sd(s,na.rm=TRUE) tripliclones.info$Estandar_desviation[i]<-de } tripliclones.info } The mistake is in de<-sd(s,na.rm=TRUE). Why?. Thanks so much from Spain
ml-r-help at epigenomics.com
2009-Mar-05 18:05 UTC
[R] Error in var(x, na.rm = na.rm) : no complete element pairs
Carlos Morales wrote:> Hello, > > I still have the same error which I have written in the Subject field, I leave here the code and I hope you can help me with this: >[removed] the lengthy code example does not make it easier to help you, in particular without the data you used. All the commented out code should have been removed before posting. My guess is that you use R < 2.8.0 and generate a vector s which contains only NAs. Try to inspect your function filter.clones by putting a browser() call somewhere before the sd() call and run it again. See ?browser and ?trace. And you could vectorize this (and other parts), e.g. the last loop would be rewritten as tripliclones.info$Estandar_desviation <- apply(tripliclones.info[ ,2:4], 1, function(x) sd(as.numeric(x), na.rm=TRUE)) Regards, Matthias R version 2.7.1 (2008-06-23)> b <- rep(NA,4) > sd(b)Error in var(x, na.rm = na.rm) : missing observations in cov/cor> sd(b, TRUE)Error in var(x, na.rm = na.rm) : no complete element pairs R version 2.8.1 (2008-12-22)> b<- rep(NA,4) > sd(b)[1] NA> sd(b, TRUE)[1] NA -- Matthias Burger Project Manager/ Biostatistician Epigenomics AG Kleine Praesidentenstr. 1 10178 Berlin, Germany phone:+49-30-24345-0 fax:+49-30-24345-555 http://www.epigenomics.com matthias.burger at epigenomics.com -- Epigenomics AG Berlin Amtsgericht Charlottenburg HRB 75861 Vorstand: Geert Nygaard (CEO/Vorsitzender) Oliver Schacht PhD (CFO) Aufsichtsrat: Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)