Reputation: 167
i am struggling with an assignment and i would like your input. note: this is a homework but when i tried to add the tag it said not to add it.. i don't want the resulting code, just suggestions on how to get this working :)
so, i have a t.test function as such:
my.t.test <- function(x,s1,s2){
x1 <- x[s1]
x2 <- x[s2]
x1 <- as.numeric(x1)
x2 <- as.numeric(x2)
t.out <- t.test(x1,x2,alternative="two.sided",var.equal=T)
out <- as.numeric(t.out$p.value)
return(out)
}
a matrix 30cols x 12k rows called data
and an annotation file containing col names and data on the colums named dataAnn
dataAnn
first column contains a list of M (male) or F (female) corresponding to the samples (or cols) in data
(that follow the same order as in dataAnn
), i have to run a t.test comparing the two samples and get the p values out
when i call
raw.pValue <- apply(data,1,my.t.test,s1=dataAnn[,1]=="M",s2=dataAnn[,1]=="F")
i get the error
Error in t.test(x1, x2, alternative = "two.sided", var.equal = T) :
unused argument(s) (alternative = "two.sided", var.equal = T)
i even tried to use
raw.pValue <- apply(data,1,my.t.test,s1=unlist(data[,1:18]),s2=unlist(data[,19:30]))
to divide the cols i want to compare but in this case i get the error
Error in x[s1] : invalid subscript type 'list'
i have been looking online, i understand that the second error is caused by an indices being a list...but this didn't really clarify it for me... any input would be appreciated!!
Upvotes: 1
Views: 3513
Reputation: 66834
You have overwritten the t.test
function. Try calling it something like my.t.test
, or when you want to call the original one use stats::t.test
(this calls the one from the stats
namespace). Remember that when you have overwritten a function you need to rm
it from your workspace before you can use the original one without specifying the namespace.
Upvotes: 1