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

StackOverflow https://stackoverflow.com/questions/22409561

  •  14-06-2023
  •  | 
  •  

Domanda

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?

È stato utile?

Soluzione

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'.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top