vegan
vegan copied to clipboard
Error in qr.fitted(qrhs, G) : 'qr' and 'y' must have the same number of rows
hello, when I run
species <- as.matrix(species) print(dim(xy)) print(dim(as.data.frame(as.matrix(base@sam_data)))) print(dim(species)) print(adonis2(xy ~ species, data = as.data.frame(as.matrix(base@sam_data))))
I get Error in qr.fitted(qrhs, G) : 'qr' and 'y' must have the same number of rows
do you know why
No, I don't know. But you do not give many hints either. What are xy
, species
and base@sam_data
and what are their dimensions? Moreover, the RHS of formula (~ species
) should be names of variables found in data
.
xy is a matrix just like this Comp 1 Comp 2 Sample1 3.626698584 1.86298075 Sample2 -1.006893073 -3.19403722 Sample3 0.082060143 2.47763831 Sample4 -0.748028447 -2.98723273 Sample5 -1.328411860 1.72429651 Sample6 1.798678420 0.52244040 Sample7 1.074809402 0.88641367 Sample8 -0.529578562 -0.95244148 Sample9 -4.789023081 0.21641650 Sample10 -1.043885947 2.48610885 Sample11 -0.007122425 0.82511560
xy has the same rows as data. data is the label data.frame. species is one col in data.
I try to change rhs to name of variable. But I use adonis2 in a function. I change character to a variable name to achieve it. But Error in model.frame.default(delete.response(terms(formula)), data, na.action = na.action) : object is not a matrix
My code is
adonis2(xy ~ as.symbol(colnames(as.data.frame(as.matrix(simphyseq@sam_data)))), data = as.data.frame(as.matrix(simphyseq@sam_data)))
What are your insights? Thank you so much!
I really do not understand how you came up with such a long and winding expressions. What do you think they make? It seems that as.symbol(colnames(as.data.frame(as.matrix(simphyseq@sam_data))))
expands to the name of the first variable in data. I suggest that instead of packing together such complicated expressions, you evaluate these to simple structures before calling adonis2
. Then you can also see if these expressions really do what you think they should do. That is, see what you get from
xy # is this a matrix, what are its dims
as.symbol(colnames(as.data.frame(as.matrix(simphyseq@sam_data)))) # what is the name you get here
as.data.frame(as.matrix(simphyseq@sam_data)) # does this exist, what are its dims
Also remember that as.symbol
returns only the first element of a vector, or one single name. You can see this by comparing output of letters
and as.symbol(letters)
.