Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RDA, Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric, when data is numeric?

Tags:

r

rda

vegan

I want to perform a rda in R, using vegan.

My code looks like this:

species<- read.delim("springspecies1.txt", header=T)
envdata<- read.delim("springenv1.txt", header=T)

RDA <- rda(species~Temperature + Salinity + O2 + Phosphate + Nitrate + Silica, envdata, scale=T, na.action=na.omit)

and I get the error message:

Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric

when I check my data I get:

sapply(species, mode)
      Station          Year         Month     S.marinoi      C.tripos 
    "numeric"     "numeric"     "numeric"     "numeric"     "numeric" 
      P.alata     P.seriata    R.setigera    C.pelagica D.confervacea 
    "numeric"     "numeric"     "numeric"     "numeric"     "numeric" 
  C.decipiens    P.farcimen       C.furca 
    "numeric"     "numeric"     "numeric"

There are no NA or blanks in my data set. But it seems that the species data set is the problem. I compiled a new data set with the species, but I get the same problem again. Any ideas?

like image 240
user3420443 Avatar asked Mar 14 '14 15:03

user3420443


People also ask

What is colMeans function r?

The colMeans() function in R can be used to calculate the mean of several columns of a matrix or data frame in R.


1 Answers

Instead of using 'mode', you should be testing with 'class'. You probably have a factor column. They are of mode numeric but test FALSE with 'is.numeric'.

like image 147
IRTFM Avatar answered Sep 21 '22 19:09

IRTFM