2
votes

I used Vegan R package to analyze my data. But I have some missing value in my data, so when I use function rda. The output is like this:

#RDA
pca.rda <- rda(pcan ~ ., data = all.env, scale = FALSE)

Error in na.fail.default(list(Plot = c(7L, 8L, 9L, 34L, 35L, 36L, 61L, : missing values in object

Do anyone know how to do with these missing value?

I have missing value only in two columns of data, see below

all.env$SM
[1] 21.92 25.92 27.47 30.49 31.18 29.54 30.06    NA 24.17 27.52 30.29 24.25 28.61 34.57 33.63
[16]    NA    NA    NA 23.52 23.52 28.69 29.41 32.68 30.29    NA    NA    NA 13.35 11.33 17.59
[31] 26.39 27.44 24.47 21.09    NA 15.61 19.46 21.09 13.60 25.97 26.34    NA    NA    NA    NA
[46] 17.64 16.01 16.31 22.05 23.46 22.39    NA    NA    NA 13.23 19.36 17.27 29.34 28.31 30.13
[61] 20.48    NA 20.20 19.87 20.69 16.30 27.45 24.55    NA    NA    NA    NA 19.37 21.14 16.81
[76] 24.13 26.09 25.79    NA    NA    NA

all.env$ST
[1] 19.40 19.70 19.69 20.86 19.95 20.22 21.04    NA 21.79 20.34 19.55 20.14 21.12 21.03 20.78
[16]    NA    NA    NA 20.24 20.28 20.43 21.52 21.56 21.11    NA    NA    NA 17.63 18.11 18.97
[31] 18.27 18.19 19.22 19.46    NA 20.16 18.93 18.81 19.50 19.70 19.99    NA    NA    NA    NA
[46] 18.06 18.43 18.83 20.56 20.78 19.42    NA    NA    NA    NA 18.12    NA    NA 18.09    NA
[61] 19.11    NA 19.90 18.78    NA 19.48 19.62    NA    NA    NA    NA    NA 17.91 18.18 18.61
[76] 20.44 21.17 19.35    NA    NA    NA

first I reclass some data into factor

all.env$Site<-as.factor(all.env$Site)    
all.env$Type <- as.factor(all.env$Type)    
all.env$Slope<- as.factor(all.env$Slope)    
summary(all.env)

do PCA

pcan <- rda(pcaall[7:72])    
pcan

RDA

pca.rda <- rda(pcan ~ .,data = all.env, scale=FALSE)

After this I got error message

Error in na.fail.default(list(Plot = c(7L, 8L, 9L, 34L, 35L, 36L, 61L, : missing values in object

I also tried to use Median value of these two column.

`all.env$SM[is.na(all.env$SM)] <- median(all.env$SM, na.rm=TRUE)`
`all.env$ST[is.na(all.env$ST)] <- median(all.env$ST, na.rm=TRUE)`

RDA

`pca.rda <- rda(pcan ~ .,data = all.env, scale=FALSE)`

Still, I got error message.

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

2
Please provide some example data and explain the steps you took to get this error. If your method requires that you have no missing values in your data then you will need to impute those yourself: en.wikipedia.org/wiki/Imputation_(statistics) - niczky12
Thanks, please see my edit. - Zhuli

2 Answers

2
votes

You could try replacing the missing (NA) data with the median value from the data set:

all.env[is.na(all.env)] <- median(all.env, na.rm=TRUE)
-2
votes

It is not clear to me how your data looks like, but this error (x must be numeric) is always related to non-numeric values inside the dataframe. PCA and RDA doesn't work with factors, only numeric variables.

First, you should import your data paying attention to that. If you import the data from a .txt file, just fill the missing value cells with NA and R will create numeric variables. If you are using .xls(x) file, packages requires different treatments to NA values (read the help).

That will probably solve the problem. But more info will make easier to help.