I have a problem using data from a tab delimited data file imported with read.delim
.
Most of the columns contain numerical data which I need to do a
You say "Most of the columns contain numerical data". That's the problem. Only when all columns contain numerical data, can the function apply used without changing the data type. If there is any non-numerical data in other columns, you should change the data type in the function apply:
pvalue<-apply(x,1,ttest<-function(tmp {
if(length(unique(c(tmp[5],tmp[7],tmp[9])))!=1 &&
length(unique(c(tmp[11],tmp[13],tmp[15])))!=1)
t.test(c(as.numeric(tmp[5]),as.numeric(tmp[7]),
as.numeric(tmp[9])), c(as.numeric(tmp[11]),
as.numeric(tmp[13]),as.numeric(tmp[15])))$p.value
else NA})