Without phylum_ea it's hard to pinpoint the cause. Generally, though it's a dimension problem with a mismatch between LIST and row and it's not fruitful to specify exactly where by just eyeballing.
There are three ways to approach this, with varying degrees of mental effort.
-
Debugging the
Rsetup. I can help with a complete areprex. See the FAQ that includes representative data. -
This eyeballs as a perfectly good
forloop for aCderived language, but neitherCor, say,Pythonhave to worry about distinctions between the.Globaland.Localenvironments. It's always possible to make a practice of writing loops in this style in a language that supports the style natively and to use{reticulate}andPythonor{Rcpp}andCwithin anRsession. -
Set aside the code temporarily and reconsider the problem functionally in terms of school algebra—f(x) = y
where
x is phylum_e
y is a tabular presentation of the five test statistics developed in the for loop
f is a function or composite function (f(g(x)) that will transform x into y
x can be inspected in its final form to conform that the objects needed can be transformed into the statistics
y is given as LIST which is dim() 4 5
y constrains f in that the return value of f must fit within y. Philosophically, y is output modified only by being populated with values within its structure it may be build programmatically, but it is known in advance what typeof everything is and where it slots dimensionally.
Considered this way, f must place either five variable vectors column wise or four row records row wise. If done in a for loop with
then
must have have length five. Consider however the difference in the length of the first and second row objects below
library(car)
#> Loading required package: carData
l <- lm(conformity ~ fcategory*partner.status, data=Moore,
contrasts=list(fcategory=contr.sum, partner.status=contr.sum))
Am <- Anova(l,type=2)[,3]
names(Am) <- rownames(Anova(l))
Sm <- summary(l)
tvalue <- Sm$tTable[,4]
pvalue <- Sm$tTable[,5]
(row <- c(1,2,3,4,5)) |> length()
#> [1] 5
(row <- c(Am,2,3,4,5)) |> length()
#> [1] 8
Am
#> fcategory partner.status fcategory:partner.status
#> 0.2769585 10.1206922 4.1846233
#> Residuals
#> NA
Created on 2023-03-23 with reprex v2.0.2
The algebraic style of analysis, focusing on the what rather than the how is analytic and analysis is hard-seeming, static, less fluid and intuitive than how we often approach problems, which is to blaze ahead looking for some button to push differently to "make it work."