Entering edit mode
5.5 years ago
rida.rehman
•
0
Hi, I am having some problems in making this function work. I have started using R two months back so not familiar with most things. My data has first col as treatment with factors. From second column the numerical values begin.
dm<-model.matrix(~0+mergetotal$treatment)
colnames(dm)<-c("a","b","c","d","e")
conmat<-makeContrasts(a-b, b-c,b-d,b-e, levels = dm)
for (i in 2:seq_along(mergetotal))
{
ft[i] <- lmFit(mergetotal[i],dm)
ft2[i]<-contrasts.fit(ft[i], conmat)
ft3[i]<-eBayes(ft2[i])
svt[i]<-toptable(ft3[i], coef = 1, adjust.method = "fdr")
tvc[i]<-toptable(ft3[i], coef = 2, adjust.method = "fdr")
tvj[i]<-toptable(ft3[i], coef = 3, adjust.method = "fdr")
tvp[i]<-toptable(ft3[i], coef = 4, adjust.method = "fdr")
}
The problem is that when I use this loop it does not work but if I do it manually everything works so I assume my problem is in the first two conditions in my loop. Since I have 1440 observations, I cannot do it manually. Need help! Thanks already.
Is it possible you've just mistook how to use seq_along? I can't tell, given the incomplete code; but mergetotal looks like a data-frame to me and 2:seq_along(some_df) will throw a warning and evaluate to 2:1 = c(2, 1) because the
:
function takes two arguments of length one. Tryseq_along(mergetotal)[-1]
in place of2:seq_along(...)
.Given some vector
v
, seq_along(v) returns c(1, 2, 3, ...., length(v)). So2:seq_along(v)
would be equivalent to:
(2, c(1, 2, ..., length(v))).Yes mergetotal is a data frame with 15 (rows) and 1441 column.
data.frame': 15 obs. of 1441 variables: $ treatment: Factor w/ 5 levels "a","b","c",..: 1 1 1 2 2 2 3 3 3 4 ... $ X1 : num . . . . . $ X1440 : num
I already tried seq_along(mergetotal)[-1]. It gives me an error: row dimension of design doesn't match column dimension of data object, but if I write ft <- lmFit(mergetotal$X1,dm), it works.
In second case the same error as above appears and as in 2:seq_along : In 2:seq_along(v) : numerical expression has 1440 elements: only the first used