input data must be numeric error

attach(SudhinTest)
The following objects are masked from SudhinTest (pos = 3):

MDF, MDF.1, MDF.10, MDF.11, MDF.12, MDF.13, MDF.14, MDF.15, MDF.16,
MDF.17, MDF.18, MDF.19, MDF.2, MDF.20, MDF.21, MDF.22, MDF.23, MDF.24,
MDF.25, MDF.26, MDF.3, MDF.4, MDF.5, MDF.6, MDF.7, MDF.8, MDF.9, RPN,
RPN.1, RPN.10, RPN.11, RPN.12, RPN.13, RPN.14, RPN.15, RPN.16, RPN.17,
RPN.18, RPN.19, RPN.2, RPN.20, RPN.21, RPN.22, RPN.23, RPN.24, RPN.25,
RPN.26, RPN.3, RPN.4, RPN.5, RPN.6, RPN.7, RPN.8, RPN.9, SG, SG.1,
SG.10, SG.11, SG.12, SG.13, SG.14, SG.15, SG.16, SG.17, SG.18, SG.19,
SG.2, SG.20, SG.21, SG.22, SG.23, SG.24, SG.25, SG.26, SG.3, SG.4,
SG.5, SG.6, SG.7, SG.8, SG.9, TP, TP.1, TP.10, TP.11, TP.12, TP.13,
TP.14, TP.15, TP.16, TP.17, TP.18, TP.19, TP.2, TP.20, TP.21, TP.22,
TP.23, TP.24, TP.25, TP.26, TP.3, TP.4, TP.5, TP.6, TP.7, TP.8, TP.9,
X

dim(SudhinTest)
[1] 327 109
library(vegan)
diversity(SudhinTest, index = "shannon")
Error in diversity(SudhinTest, index = "shannon") :
input data must be numeric

Please help me to solve this eror

Use

str(SudhinTest)

to see if the data are, in fact, numeric.

Should look similarly to

str(mtcars)
#> 'data.frame':    32 obs. of  11 variables:
#>  $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
#>  $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...
#>  $ disp: num  160 160 108 258 360 ...
#>  $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...
#>  $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
#>  $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...
#>  $ qsec: num  16.5 17 18.6 19.4 17 ...
#>  $ vs  : num  0 0 1 1 0 1 0 1 1 1 ...
#>  $ am  : num  1 1 1 0 0 0 0 0 0 0 ...
#>  $ gear: num  4 4 4 3 3 3 3 4 4 4 ...
#>  $ carb: num  4 4 1 1 2 1 4 2 2 4 ...

Thank you sir...

But in my dataset first 4 column and 1 raw having text heading.

The error is

str(SudhinTest)
'data.frame': 327 obs. of 109 variables:
X : chr "" "" "" "Amaurobius sp-1 (doubt)" ... TP : chr "MON" "Bathery" "TPM-B1" "0" ...
TP.1 : chr "MON" "Bathery" "TPM-B2" "0" ... TP.2 : chr "MON" "Bathery" "TPM-B3" "0" ...
TP.3 : chr "MON" "Muthanga" "TPM-M1" "0" ... TP.4 : chr "MON" "Muthanga" "TPM-M2" "0" ...
TP.5 : chr "MON" "Muthanga" "TPM-M3" "0" ... TP.6 : chr "MON" "Kurichiad" "TPM-K1" "0" ...
TP.7 : chr "MON" "Kurichiad" "TPM-K2" "0" ... TP.8 : chr "MON" "Kurichiad" "TPM-K3" "0" ...
TP.9 : chr "POST MON" "Bathery" "TPPM-B1" "0" ... TP.10 : chr "POST MON" "Bathery" "TPPM-B2" "0" ...
TP.11 : chr "POST MON" "Bathery" "TPPM-B3" "0" ... TP.12 : chr "POST MON" "Muthanga" "TPPM-M1" "0" ...
TP.13 : chr "POST MON" "Muthanga" "TPPM-M2" "0" ... TP.14 : chr "POST MON" "Muthanga" "TPPM-M3" "0" ...
TP.15 : chr "POST MON" "Kurichiad" "TPPM-K1" "0" ... TP.16 : chr "POST MON" "Kurichiad" "TPPM-K2" "0" ...
TP.17 : chr "POST MON" "Kurichiad" "TPPM-K3" "0" ... TP.18 : chr "PRE MON" "Bathery" "TPPRM-B1" "0" ...
TP.19 : chr "PRE MON" "Bathery" "TPPRM-B2" "0" ... TP.20 : chr "PRE MON" "Bathery" "TPPRM-B3" "0" ...
TP.21 : chr "PRE MON" "Muthanga" "TPPRM-M1" "0" ... TP.22 : chr "PRE MON" "Muthanga" "TPPRM-M2" "0" ...
TP.23 : chr "PRE MON" "Muthanga" "TPPRM-M3" "0" ... TP.24 : chr "PRE MON" "Kurichiad" "TPPRM-K1" "0" ...
TP.25 : chr "PRE MON" "Kurichiad" "TPPRM-K2" "0" ... TP.26 : chr "PRE MON" "Kurichiad" "TPPRM-K3" "0" ...
SG : chr "MON" "Bathery" "SGM-B1" "0" ... SG.1 : chr "MON" "Bathery" "SGM-B2" "0" ...
SG.2 : chr "MON" "Bathery" "SGM-B3" "0" ... SG.3 : chr "MON" "Muthanga" "SGM-M1" "0" ...
SG.4 : chr "MON" "Muthanga" "SGM-M2" "0" ... SG.5 : chr "MON" "Muthanga" "SGM-M3" "0" ...
SG.6 : chr "MON" "Kurichiad" "SGM-K1" "0" ... SG.7 : chr "MON" "Kurichiad" "SGM-K2" "0" ...
SG.8 : chr "MON" "Kurichiad" "SGM-K3" "0" ... SG.9 : chr "POST MON" "Bathery" "SGPM-B1" "0" ...
SG.10 : chr "POST MON" "Bathery" "SGPM-B2" "0" ... SG.11 : chr "POST MON" "Bathery" "SGPM-B3" "0" ...
SG.12 : chr "POST MON" "Muthanga" "SGPM-M1" "0" ... SG.13 : chr "POST MON" "Muthanga" "SGPM-M2" "0" ...
SG.14 : chr "POST MON" "Muthanga" "SGPM-M3" "0" ... SG.15 : chr "POST MON" "Kurichiad" "SGPM-K1" "0" ...
SG.16 : chr "POST MON" "Kurichiad" "SGPM-K2" "0" ... SG.17 : chr "POST MON" "Kurichiad" "SGPM-K3" "0" ...
SG.18 : chr "PRE MON" "Bathery" "SGPRM-B1" "0" ... SG.19 : chr "PRE MON" "Bathery" "SGPRM-B2" "0" ...
SG.20 : chr "PRE MON" "Bathery" "SGPRM-B3" "0" ... SG.21 : chr "PRE MON" "Muthanga" "SGPRM-M1" "0" ...
SG.22 : chr "PRE MON" "Muthanga" "SGPRM-M2" "0" ... SG.23 : chr "PRE MON" "Muthanga" "SGPRM-M3" "0" ...
SG.24 : chr "PRE MON" "Kurichiad" "SGPRM-K1" "0" ... SG.25 : chr "PRE MON" "Kurichiad" "SGPRM-K2" "0" ...
SG.26 : chr "PRE MON" "Kurichiad" "SGPRM-K3" "0" ... MDF : chr "MON" "Bathery" "MDFM-B1" "0" ...
MDF.1 : chr "MON" "Bathery" "MDFM-B2" "0" ... MDF.2 : chr "MON" "Bathery" "MDFM-B3" "0" ...
MDF.3 : chr "MON" "Muthanga" "MDFM-M1" "0" ... MDF.4 : chr "MON" "Muthanga" "MDFM-M2" "0" ...
MDF.5 : chr "MON" "Muthanga" "MDFM-M3" "0" ... MDF.6 : chr "MON" "Kurichiad" "MDFM-K1" "0" ...
MDF.7 : chr "MON" "Kurichiad" "MDFM-K2" "0" ... MDF.8 : chr "MON" "Kurichiad" "MDFM-K3" "0" ...
MDF.9 : chr "POSTMON" "Bathery" "MDFPM-B1" "0" ... MDF.10: chr "POSTMON" "Bathery" "MDFPM--B2" "0" ...
MDF.11: chr "POSTMON" "Bathery" "MDFPM--B3" "0" ... MDF.12: chr "POSTMON" "Muthanga" "MDFPM-N-M1" "0" ...
MDF.13: chr "POSTMON" "Muthanga" "MDFPM--M2" "0" ... MDF.14: chr "POSTMON" "Muthanga" "MDFPM--M3" "0" ...
MDF.15: chr "POSTMON" "Kurichiad" "MDFPM--K1" "0" ... MDF.16: chr "POSTMON" "Kurichiad" "MDFPM--K2" "0" ...
MDF.17: chr "POSTMON" "Kurichiad" "MDFPM--K3" "0" ... MDF.18: chr "PRE MON" "Bathery" "MDFPRM-B1" "0" ...
MDF.19: chr "PRE MON" "Bathery" "MDFPRM-B2" "0" ... MDF.20: chr "PRE MON" "Bathery" "MDFPRM-B3" "0" ...
MDF.21: chr "PRE MON" "Muthanga" "MDFPRM-M1" "0" ... MDF.22: chr "PRE MON" "Muthanga" "MDFPRM-M2" "0" ...
MDF.23: chr "PRE MON" "Muthanga" "MDFPRM-M3" "0" ... MDF.24: chr "PRE MON" "Kurichiad" "MDFPRM-K1" "0" ...
MDF.25: chr "PRE MON" "Kurichiad" "MDFPRM-K2" "0" ... MDF.26: chr "PRE MON" "Kurichiad" "MDFPRM-K3" "0" ...
RPN : chr "MON" "Bathery" "RPNM-B1" "0" ... RPN.1 : chr "MON" "Bathery" "RPNM-B2" "0" ...
RPN.2 : chr "MON" "Bathery" "RPNM-B3" "0" ... RPN.3 : chr "MON" "Muthanga" "RPNM-M1" "0" ...
RPN.4 : chr "MON" "Muthanga" "RPNM-M2" "0" ... RPN.5 : chr "MON" "Muthanga" "RPNM-M3" "0" ...
RPN.6 : chr "MON" "Kurichiad" "RPNM-K1" "0" ... RPN.7 : chr "MON" "Kurichiad" "RPNM-K2" "0" ...
RPN.8 : chr "MON" "Kurichiad" "RPNM-K3" "0" ... RPN.9 : chr "POSTMON" "Bathery" "RPNPM-B1" "0" ...
RPN.10: chr "POSTMON" "Bathery" "RPNPM-B2" "2" ... RPN.11: chr "POSTMON" "Bathery" "RPNPM-B3" "0" ...
RPN.12: chr "POSTMON" "Muthanga" "RPNPM-M1" "0" ... RPN.13: chr "POSTMON" "Muthanga" "RPNPM-M2" "0" ...
RPN.14: chr "POSTMON" "Muthanga" "RPNPM-M3" "0" ... RPN.15: chr "POSTMON" "Kurichiad" "RPNPM-K1" "0" ...
$ RPN.16: chr "POSTMON" "Kurichiad" "RPNPM-K2" "0" ...
[list output truncated]

Please help me

Just so. All of the variables shown are character, not numeric as required by vegan::diversity

Run below and compare

suppressPackageStartupMessages({
  library(vegan)
})

data(BCI)
str(BCI)
#> 'data.frame':    50 obs. of  225 variables:
#>  $ Abarema.macradenia              : int  0 0 0 0 0 0 0 0 0 1 ...
#>  $ Vachellia.melanoceras           : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Acalypha.diversifolia           : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Acalypha.macrostachya           : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Adelia.triloba                  : int  0 0 0 3 1 0 0 0 5 0 ...
#>  $ Aegiphila.panamensis            : int  0 0 0 0 1 0 1 0 0 1 ...
#>  $ Alchornea.costaricensis         : int  2 1 2 18 3 2 0 2 2 2 ...
#>  $ Alchornea.latifolia             : int  0 0 0 0 0 1 0 0 0 0 ...
#>  $ Alibertia.edulis                : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Allophylus.psilospermus         : int  0 0 0 0 1 0 0 0 0 0 ...
#>  $ Alseis.blackiana                : int  25 26 18 23 16 14 18 14 16 14 ...
#>  $ Amaioua.corymbosa               : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Anacardium.excelsum             : int  0 0 0 0 0 0 0 1 0 0 ...
#>  $ Andira.inermis                  : int  0 0 0 0 1 1 0 0 1 0 ...
#>  $ Annona.spraguei                 : int  1 0 1 0 0 0 0 1 1 0 ...
#>  $ Apeiba.glabra                   : int  13 12 6 3 4 10 5 4 5 5 ...
#>  $ Apeiba.tibourbou                : int  2 0 1 1 0 0 0 1 0 0 ...
#>  $ Aspidosperma.desmanthum         : int  0 0 0 1 1 1 0 0 0 1 ...
#>  $ Astrocaryum.standleyanum        : int  0 2 1 5 6 2 2 0 2 1 ...
#>  $ Astronium.graveolens            : int  6 0 1 3 0 1 2 2 0 0 ...
#>  $ Attalea.butyracea               : int  0 1 0 0 0 1 1 0 0 0 ...
#>  $ Banara.guianensis               : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Beilschmiedia.pendula           : int  4 5 7 5 8 6 5 9 11 14 ...
#>  $ Brosimum.alicastrum             : int  5 2 4 3 2 2 6 4 3 6 ...
#>  $ Brosimum.guianense              : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Calophyllum.longifolium         : int  0 2 0 2 1 2 2 2 2 0 ...
#>  $ Casearia.aculeata               : int  0 0 0 0 0 0 0 1 0 0 ...
#>  $ Casearia.arborea                : int  1 1 3 2 4 1 2 3 9 7 ...
#>  $ Casearia.commersoniana          : int  0 0 1 0 1 0 0 0 1 0 ...
#>  $ Casearia.guianensis             : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Casearia.sylvestris             : int  2 1 0 0 0 3 1 0 1 1 ...
#>  $ Cassipourea.guianensis          : int  2 0 1 1 3 4 4 0 2 1 ...
#>  $ Cavanillesia.platanifolia       : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Cecropia.insignis               : int  12 5 7 17 21 4 0 7 2 16 ...
#>  $ Cecropia.obtusifolia            : int  0 0 0 0 1 0 0 2 0 2 ...
#>  $ Cedrela.odorata                 : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Ceiba.pentandra                 : int  0 1 1 0 1 0 0 1 0 1 ...
#>  $ Celtis.schippii                 : int  0 0 0 2 2 0 1 0 0 0 ...
#>  $ Cespedesia.spathulata           : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Chamguava.schippii              : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Chimarrhis.parviflora           : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Maclura.tinctoria               : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Chrysochlamys.eclipes           : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Chrysophyllum.argenteum         : int  4 1 2 2 6 2 3 2 4 2 ...
#>  $ Chrysophyllum.cainito           : int  0 0 0 0 0 0 1 0 0 0 ...
#>  $ Coccoloba.coronata              : int  0 0 0 1 2 0 0 1 2 1 ...
#>  $ Coccoloba.manzinellensis        : int  0 0 0 0 0 0 0 2 0 0 ...
#>  $ Colubrina.glandulosa            : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Cordia.alliodora                : int  2 3 3 7 1 1 2 0 0 2 ...
#>  $ Cordia.bicolor                  : int  12 14 35 23 13 7 5 10 7 13 ...
#>  $ Cordia.lasiocalyx               : int  8 6 6 11 7 6 6 3 0 4 ...
#>  $ Coussarea.curvigemma            : int  0 0 0 1 0 2 1 0 1 1 ...
#>  $ Croton.billbergianus            : int  2 2 0 11 6 0 0 4 2 0 ...
#>  $ Cupania.cinerea                 : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Cupania.latifolia               : int  0 0 0 1 0 0 0 0 0 0 ...
#>  $ Cupania.rufescens               : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Cupania.seemannii               : int  2 2 1 0 3 0 1 2 2 0 ...
#>  $ Dendropanax.arboreus            : int  0 3 6 0 5 2 1 6 1 3 ...
#>  $ Desmopsis.panamensis            : int  0 0 4 0 0 0 0 0 0 1 ...
#>  $ Diospyros.artanthifolia         : int  1 1 1 1 0 0 0 0 0 1 ...
#>  $ Dipteryx.oleifera               : int  1 1 3 0 0 0 0 2 1 2 ...
#>  $ Drypetes.standleyi              : int  2 1 2 0 0 0 0 0 0 0 ...
#>  $ Elaeis.oleifera                 : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Enterolobium.schomburgkii       : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Erythrina.costaricensis         : int  0 0 0 0 0 3 0 0 1 0 ...
#>  $ Erythroxylum.macrophyllum       : int  0 1 0 0 0 0 0 1 1 1 ...
#>  $ Eugenia.florida                 : int  0 1 0 7 2 0 0 1 1 3 ...
#>  $ Eugenia.galalonensis            : int  0 0 0 0 0 0 0 1 0 0 ...
#>  $ Eugenia.nesiotica               : int  0 0 1 0 0 0 5 4 3 0 ...
#>  $ Eugenia.oerstediana             : int  3 2 5 1 5 2 2 3 3 3 ...
#>  $ Faramea.occidentalis            : int  14 36 39 39 22 16 38 41 33 42 ...
#>  $ Ficus.colubrinae                : int  0 1 0 0 0 0 0 0 0 0 ...
#>  $ Ficus.costaricana               : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Ficus.insipida                  : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Ficus.maxima                    : int  1 0 0 0 0 0 0 0 0 0 ...
#>  $ Ficus.obtusifolia               : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Ficus.popenoei                  : int  0 0 0 0 0 0 1 0 0 0 ...
#>  $ Ficus.tonduzii                  : int  0 0 1 2 1 0 0 0 0 0 ...
#>  $ Ficus.trigonata                 : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Ficus.yoponensis                : int  1 0 0 0 0 1 1 0 0 0 ...
#>  $ Garcinia.intermedia             : int  0 1 1 3 2 1 2 2 1 0 ...
#>  $ Garcinia.madruno                : int  4 0 0 0 1 0 0 0 0 1 ...
#>  $ Genipa.americana                : int  0 0 1 0 0 0 1 0 1 1 ...
#>  $ Guapira.myrtiflora              : int  3 1 0 1 1 7 3 1 1 1 ...
#>  $ Guarea.fuzzy                    : int  1 1 0 1 3 0 0 2 0 3 ...
#>  $ Guarea.grandifolia              : int  0 0 0 0 0 0 0 1 0 0 ...
#>  $ Guarea.guidonia                 : int  2 6 2 5 3 4 4 0 1 5 ...
#>  $ Guatteria.dumetorum             : int  6 16 6 3 9 7 8 6 2 2 ...
#>  $ Guazuma.ulmifolia               : int  0 0 0 1 0 0 0 0 0 0 ...
#>  $ Guettarda.foliacea              : int  1 5 1 2 1 0 0 4 1 3 ...
#>  $ Gustavia.superba                : int  10 5 0 1 3 1 8 4 4 4 ...
#>  $ Hampea.appendiculata            : int  0 0 1 0 0 0 0 0 2 1 ...
#>  $ Hasseltia.floribunda            : int  5 9 4 11 9 2 7 6 3 4 ...
#>  $ Heisteria.acuminata             : int  0 0 0 0 1 1 0 0 0 0 ...
#>  $ Heisteria.concinna              : int  4 5 4 6 4 8 2 5 1 5 ...
#>  $ Hirtella.americana              : int  0 0 0 0 0 0 0 0 0 0 ...
#>  $ Hirtella.triandra               : int  21 14 5 4 6 6 7 14 8 7 ...
#>  $ Hura.crepitans                  : int  0 0 0 0 0 2 1 1 0 0 ...
#>  $ Hieronyma.alchorneoides         : int  0 2 0 0 0 0 0 0 1 0 ...
#>   [list output truncated]
#>  - attr(*, "original.names")= chr [1:225] "Abarema.macradenium" "Acacia.melanoceras" "Acalypha.diversifolia" "Acalypha.macrostachya" ...
claude <- diversity(BCI, "shannon")

Dear sir,
How to convert char to numeric?

Before proceeding to how, some thought should be devoted to what.

Taking the BCI dataset as a model, the goal should be to produce a data frame with a number of columns, each representing a single species, with the rows representing an integer, apparently,perhaps indicating a count at a particular place or point of time. (You can see that I'm approaching this abstractly.)

Compare with SudhinTest, which has the following organization

"MON", "Bathery","TPM−B2","0"\dots

For purposes of illustration, I will assume that Bathery takes the place of the apparent species in BCI, MONandTPM-B2are extraneous and0` is the beginning of a vector of integers that is to be isolated.

If I have read this correctly, each of the variables (saving, perhaps, X) would look similarly to

obj <- c("MON", "Bathery","TPM−B2",as.character(sample(0:50,20)))
#>  [1] "MON"     "Bathery" "TPM−B2"  "33"      "24"      "42"      "11"     
#>  [8] "4"       "22"      "37"      "45"      "32"      "35"      "39"     
#> [15] "18"      "1"       "0"       "29"      "14"      "36"      "6"      
#> [22] "49"      "10"

(In this realization, there would be 23, rather than 327 observations, but the principle is the same.)

To construct a usable data object, something along the lines of

obj <- c(obj[2],as.numeric(obj[4:length(obj)]))

would start the process, and from there it would have to be cast further.

That will prove tedious and shouldn't be undertaken if the same result can be achieved more directly.

How is SudhinTest derived? Is it externally provided or did you construct it from other data?

This is data is uploaded using excel

Try using the pivot function in Excel to rotate the data so that the numeric columns are vertical.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.