R statistics: problem with simple column vector

前端 未结 3 833
星月不相逢
星月不相逢 2021-01-18 07:40

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

3条回答
  •  一生所求
    2021-01-18 07:53

    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})
    

提交回复
热议问题