vegan doesn't recognise column names, but it also does recognise them

Viewed 32

I'm trying to run RDA analysis using the R package 'vegan'

If I go with the below, using column headers, I get the error "object "width" not recognised". Suggesting that I haven't imported column headers properly.

rda(width+height~age+weight, data=mydata)

But

if I go with the below, it works, so obviously it recognises headers

rda(mydata$width+mydata$height~mydata$age+mydata$weight)

Similarly, other packages recognise headers for example the below works fine.

ggplot(mydata,aes(height, width))

Presumably it's an issue with the use of "data=mydata". I'm baffled and feel it's probably something super simple I'm overlooking, but I have tried and tried to no avail. It was going fine the other day.

1 Answers

As per the help page of rda the left hand side of your formula should be a community data matrix, and data should specify a data frame containing the variables on the right hand side of the formula.

As such, when you pass column names to the left hand side of the formula (e.g. your first line of code), rda is not looking within mydata for those columns and so fails.

In your second line of code you specify where width and height are found, so it is able to run.

You could run it like this:

response <- data.frame(height=mydata$height,width=mydata$width)
rda(response ~ age + weight, data=mydata)

Have a look through the documentation for cca/rda and you'll see example code - try to get your data into the same format as the examples.

Related