Error with t-test

余生长醉 提交于 2019-12-11 16:44:55

问题


I'm having errors with the normal t-test:

  data <- read.table("/Users/vdas/Documents/RNA-Seq_Smaples_Udine_08032013/GBM_29052013/UD_RP_25072013/filteredFPKM_matrix.txt",sep="",header=TRUE,stringsAsFactors=FALSE)

  PGT <- cbind(data[,2],data[,7],data[,24])
  PDGT <- cbind(data[,6],data[,8])
  pval2 <- NULL
  for(i in 1:length(PGT[,1])){
     pval2 <- c(pval2,t.test(as.numeric(PDGT[i,]),as.numeric(PGT[i,]))$p.value)
     print(i)
  }

Error:

Error in t.test.default(as.numeric(PDGT[i, ]), as.numeric(PGT[i, ])) : 
  not enough 'x' observations

I cannot understand what went wrong with the vector. Can you please tell me? I have not been able to figure it out .


回答1:


Most likely your data have NA values. For example: -

x<-rep(NA,4)
t.test(x)

Error in t.test.default(x) : not enough 'x' observations



回答2:


From you comment, It seems that error come due to the missing value. You can exclude the missing values by setting na.rm=TRUE. Ref:- Missing value . Before posting R question take a look at How to make a great R reproducible example?




回答3:


To remove NA values you do:

> a <- sample(c(NA, 1:5), 20, replace = TRUE)
> a
 [1] NA  1  2 NA  1  5  4  4  3  3  2  4 NA  4 NA NA  1  2 NA  5
> b <- na.omit(a)
> b
 [1] 1 2 1 5 4 4 3 3 2 4 4 1 2 5


来源:https://stackoverflow.com/questions/18075401/error-with-t-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!