I am trying to make a multi-dimensional ANOVA with the manova function in R. My problem is that I am trying to find a way to pass a list of dependent variables without typing them all manually, as there are many and they have terrible names. My data is in a data frame, where βunitβ is a dependent variable (coefficient), and the remaining columns are various numerical response variables. eg.
unit C_pct Cln C_N_mol Cnmolln C_P_mol N_P_mol 1 C 48.22 3.88 53.92 3.99 3104.75 68.42 2 C 49.91 3.91 56.32 4.03 3454.53 62.04 3 C 50.75 3.93 56.96 4.04 3922.01 69.16 4 SH 50.72 3.93 46.58 3.84 2590.16 57.12 5 SH 51.06 3.93 43.27 3.77 2326.04 53.97 6 SH 48.62 3.88 40.97 3.71 2357.16 59.67
If I write a mans call as
fit <- manova(cbind(C_pct, Cln) ~ unit, data = plots)
it works fine, but I would like to be able to skip a long list of columns without naming them one by one, something like
fit <- manova(cbind(colnames(plots[5:32])) ~ unit, data = plots)
or
fit <- manove(cbind(plots[,5:32]) ~ unit, data = plots)
I get an error
"Error in model.frame.default(formula = as.matrix(cbind(colnames(plots[5:32]))) ~ : variable lengths differ (found for 'unit')
I am sure because I am using cbind incorrectly but cannot understand. Any help is appreciated! Sorry if formatting is rude, this is my first question.
EDIT: Both methods (all 3, actually) work. thanks everyone!
source share