Error in t-testing
I am having errors with a 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)
}
Mistake:
Error in t.test.default(as.numeric(PDGT[i, ]), as.numeric(PGT[i, ])) :
not enough 'x' observations
I can't figure out what went wrong with the vector. Could you tell me? I haven't been able to figure it out.
0
vchris_ngs
source
to share
3 answers
Chances are your data matters NA
. For example: -
x<-rep(NA,4)
t.test(x)
Error in t.test.default(x) : not enough 'x' observations
+3
fkliron
source
to share
From your comment. It looks like the error comes from a missing value. You can exclude missing values ββby setting na.rm=TRUE
. Ref: - Missing value . Before posting the R question, take a look at How to make a great example of reproducible R?
0
nKandel
source
to share
To remove values NA
:
> 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
0
maximus
source
to share