1

I have an abundance dataframe improved as a csv with column and row headers. When imported, and running str(data) it shows each row as int. I can't use vegan's package specaccum unless the data is numeric. After converting my dataframe into numeric it is still producing the following error:

Error in colSums(x) : 'x' must be numeric

My sample and code:

Structure of my dataframe before any conversion:

> str(data)
'data.frame':   180 obs. of  727 variables:
 $ Sample                 : Factor w/ 180 levels "Sample1","Sample2",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ Abrostola              : int  0 0 0 0 0 0 0 0 0 0 ...
 $ Abrus                  : int  0 0 1 0 0 0 0 0 0 0 ...
 $ Acanthamoeba           : int  0 0 0 0 0 0 0 0 0 0 ...
 $ Acanthopagrus          : int  0 0 0 0 0 0 1 0 0 0 ...
 $ Acetilactobacillus     : int  0 1 0 0 0 0 0 0 0 0 ...
 $ Acetobacter            : int  0 0 0 0 0 0 0 0 0 0 ...
 

Then:

data2 <- data[-1] ## to get rid of factor column
data2 <- lapply(data2, as.numeric)
> str(data2)
List of 726
 $ Abrostola              : num [1:180] 0 0 0 0 0 0 0 0 0 0 ...
 $ Abrus                  : num [1:180] 0 0 1 0 0 0 0 0 0 0 ...
 $ Acanthamoeba           : num [1:180] 0 0 0 0 0 0 0 0 0 0 ...
 $ Acanthopagrus          : num [1:180] 0 0 0 0 0 0 1 0 0 0 ...
 $ Acetilactobacillus     : num [1:180] 0 1 0 0 0 0 0 0 0 0 ...
 $ Acetobacter            : num [1:180] 0 0 0 0 0 0 0 0 0 0 ...
 $ Achromobacter          : num [1:180] 0 0 0 0 0 0 0 0 0 0 ...
 $ Acinetobacter          : num [1:180] 0 0 0 0 0 0 0 0 0 0 ...

Next I tried running the very basic vegan command:

mycurve <- specaccum(comm = data2, method = "random", permutations = "1000")

But it gives the same error. I don't get it - my df is clearly converted to numeric so what is the issue??

EDIT

Prior to fixing my dataframe into numeric, I was using:

mycurve <- specaccum(comm = data[-1], method = "random", permutations = "1000") ## without prior removal of factor column

But it was giving the following error:

Error in nperm + EPS : non-numeric argument to binary operator
$ Acetobacter            : num [1:180] 0 0 0 0 0 0 0 0 0 0 ...

I am not sure why it is targeting this particular column, it looks exactly the same as everything else. No columns are empty (i.e. no column sums equal 0 as I thought that would be causing an issue). I checked for weird symbols/whitespace - the columns do not have anything out of the ordinary. There are no empty cells either with "NA".

Output of dput(head(data)) but due to body limit in this post I had to truncate the output.

structure(list(Sample = structure(1:6, .Label = c("Sample1", "Sample2", 
"Sample3", "Sample4", "Sample5", "Sample6", "Sample180"), class = "factor"), Abrostola = c(0L, 
0L, 0L, 0L, 0L, 0L), Abrus = c(0L, 0L, 1L, 0L, 0L, 0L), Acanthamoeba = c(0L, 
0L, 0L, 0L, 0L, 0L), Acanthopagrus = c(0L, 0L, 0L, 0L, 0L, 0L
), Acetilactobacillus = c(0L, 1L, 0L, 0L, 0L, 0L), Acetobacter = c(0L, 
0L, 0L, 0L, 0L, 0L), Achromobacter = c(0L, 0L, 0L, 0L, 0L, 0L
), Acinetobacter = c(0L, 0L, 0L, 0L, 0L, 0L), Acipenser = c(0L, 
0L, 0L, 0L, 0L, 0L), Acomys = c(0L, 0L, 0L, 0L, 0L, 0L), Acremonium = c(0L, 
0L, 0L, 0L, 0L, 0L), Acromyrmex = c(0L, 0L, 0L, 0L, 0L, 0L), 
    Acropora = c(0L, 0L, 0L, 0L, 0L, 0L), Actinidia = c(0L, 0L, 
    0L, 0L, 0L, 0L), Actinobacillus = c(0L, 0L, 0L, 0L, 0L, 0L
    ), Acyrthosiphon = c(0L, 0L, 0L, 0L, 0L, 0L), Acytostelium = c(0L, 
    1L, 0L, 0L, 0L, 0L), Aedes = c(0L, 0L, 0L, 0L, 0L, 0L), Aegilops = c(0L, 
    0L, 0L, 0L, 0L, 0L), Aeromonas = c(0L, 0L, 0L, 0L, 5L, 0L
    ), Ageratum = c(0L, 0L, 0L, 0L, 0L, 0L), Aggregatibacter = c(0L, 
    0L, 0L, 0L, 0L, 0L), Albugo = c(0L, 0L, 0L, 0L, 0L, 0L), 
    Alcaligenes = c(0L, 0L, 0L, 0L, 0L, 0L), Alcanivorax = c(0L, 
    0L, 0L, 0L, 0L, 0L), Allygidius = c(0L, 0L, 0L, 0L, 0L, 0L
    ), Amblyraja = c(0L, 0L, 0L, 0L, 0L, 0L), Amoebogregarina = c(0L, 
    0L, 1L, 1L, 0L, 0L), Amphidinium = c(0L, 0L, 0L, 0L, 0L, 
    0L), Amphiprion = c(0L, 0L, 0L, 0L, 0L, 0L), Amphipyra = c(0L, 
    1L, 1L, 1L, 0L, 1L), Amycolatopsis = c(0L, 0L, 0L, 0L, 0L, 
    0L), Ananas = c(1L, 1L, 1L, 1L, 0L, 0L), Anas = c(0L, 0L, 
    0L, 0L, 0L, 0L), Andhravirus = c(0L, 0L, 0L, 0L, 0L, 0L), 
    Andrena = c(0L, 0L, 0L, 0L, 0L, 0L), Anolis = c(0L, 0L, 0L, 
    0L, 0L, 0L), Anopheles = c(0L, 1L, 0L, 0L, 0L, 0L), Anoplophora = c(0L, 
    0L, 0L, 0L, 0L, 0L), Anoxybacillus = c(0L, 0L, 0L, 0L, 0L, 
    0L), Anthocharis = c(0L, 1L, 2L, 1L, 0L, 1L), Aphanomyces = c(0L, 
    0L, 0L, 1L, 0L, 0L), Aphyllon = c(0L, 0L, 0L, 0L, 0L, 0L), 
    Apilactobacillus = c(2L, 0L, 0L, 0L, 0L, 0L), Apotomis = c(0L, 
    0L, 0L, 0L, 0L, 0L), Apteryx = c(0L, 0L, 0L, 0L, 0L, 0L), 
    Aquila = c(0L, 0L, 0L, 0L, 0L, 0L), Arabidopsis = c(0L, 0L, 
    0L, 0L, 0L, 0L), Arabis = c(0L, 0L, 0L, 0L, 0L, 0L), Arachis = c(0L, 
    0L, 0L, 0L, 0L, 0L), Arctia = c(0L, 0L, 0L, 0L, 0L, 0L)), row.names = c(NA, 6L), class = "data.frame")

SOLVED

While the code I was using for mycurve was working with other method options and quoting permutations, simply removing the quotes for permutations along with method random worked. Did not even need to convert the data into numeric.

mycurve <- specaccum(comm = data[-1], method = "random", permutations = 1000) ## REMOVED QUOTES IN PERMUTATIONS and used with INT dataframe
7
  • try: specaccum(comm = data[[-1]], method = "random", permutations = "1000") Commented Aug 10, 2021 at 18:05
  • Didn't work. Shows Error in .subset2(x, i, exact = exact) : attempt to select more than one element in get1index <real> Commented Aug 10, 2021 at 18:06
  • I think your data2 is a list object. Please convert it to a dataframe. Commented Aug 10, 2021 at 18:20
  • Oh yea I didn't catch that. I converted it into a dataframe of numeric but the original error came back! see my post for an update of what I just did. Commented Aug 10, 2021 at 18:32
  • Actually I realized again I did a mistake in converting to a dataframe, it is introducing an index column. Gotta fix this...removed my previous update for now. Commented Aug 10, 2021 at 18:37

1 Answer 1

1

According to ?specaccum

permutations - Number of permutations with method = "random". Usually an integer giving the number permutations, but can also be a list of control values for the permutations as returned by the function how, or a permutation matrix where each row gives the permuted indices.

 specaccum(comm = data[-1], method = "random", permutations = 1000)

-ouput

Species Accumulation Curve
Accumulation method: random, with 719 permutations
Call: specaccum(comm = data[-1], method = "random", permutations = 1000) 

                                                        
Sites    1.000000 2.000000 3.000000 4.000000 5.000000  6
Richness 3.502086 5.731572 7.297636 8.598053 9.831711 11
sd       1.894776 1.483049 1.228892 1.143491 0.897720  0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.