'R code error - Error arguments implying differing number of rows: 35, 13

I am creating an NMDS plot and first I need to create a dataframe with the scores from the individual sites. This is my NMDS code:

nmds_results <- metaMDS(comm = ds_laverstock[,c(2,4:10, 12, 14:17)], distance = "bray")

And then this is the code to create the dataframe:

data_scores <- as.data.frame(scores(nmds_results))

But R keeps coming up with this error:

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 35, 13

This is a sample of my data. I looked at the length of all the columns and they're all 35. Not sure if the 0's are affecting making a dataframe.

# A tibble: 35 x 18
   month_season   mar artf_barr    ber   cal    cpg   dpg  dran   dry
   <chr>        <dbl>     <dbl>  <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl>
 1 april_2013   3.27          0 0      0      0      0        0     0
 2 april_2014   0.201         0 0      0      0      0        0     0
 3 april_2015   0.220         0 0      0      0      9.73     0     0
 4 april_2016   0             0 0      0      2.13   0        0     0
 5 april_2017   0.467         0 0      0      0      0        0     0
 6 april_2018   1.38          0 0.0496 0      7.12   0        0     0
 7 april_2019   2.00          0 0      1.12   0      0        0     0
 8 april_2020   1.27          0 0      0.492  0.485 18.4      0     0
 9 april_2021   5.13          0 0      1.21  29.7   15.1      0     0
10 april_2022   2.94          0 0.232  1.84   0     30.1      0     0
# ... with 25 more rows, and 9 more variables: mpg <dbl>, myr <dbl>,
#   pg <dbl>, pot <dbl>, ran <dbl>, sa <dbl>, si <dbl>, spg <dbl>,
#   zan <dbl>

Reproducible example

data <- mar <- c(3, 1 , 5, 0.5, 0, 0, 2, 8)
        ber <- c(0, 0, 0, 0, 3, 2.7, 9, 4)
        cal <- c(1, 2, 3, 0, 0, 0, 3, 4)
r


Solution 1:[1]

Hi i recently had the same problem with as.data.frame, i send my code to friends and have the same error in the same part that you and even ask here in stackoverflow, and seems the code is right

Today I found out the issue seems to be with a change in the newest version of vegan 2.6-2 that came out in April.

If you have the same problem that me, you should change

as.data.frame(scores(nmds)) 

to:

as.data.frame(scores(nmds)$sites)

Hope this can help you to.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Julio Poblete