r/Rlanguage • • 2d ago

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

Hi!

I'm working on a project for uni, and I just got this error message that i cannot figure out how to solve. Here is my code, and the problem occurs in the last line. I understand that the problem is with the data frame, but how can i solve it? Knowing that I will then use all_tab in an ACP

predictors <- geodata::worldclim_country(country = c('FRA',"ESP","AND"), var='bio', mask=TRUE, res= 2.5, path="")
presvals <- terra::extract(predictors, pres)
presvals_tab <- as.data.frame(presvals)

zone <- terra::ext(0, 5, 42, 45)
all <- terra::extract(predictors, zone)
summary(all)
all_tab <- as.data.frame(all)
0 Upvotes

9 comments sorted by

2

u/SprinklesFresh5693 2d ago

In which of those 5 objects are you getting the error

2

u/satvrtle 2d ago

The error appears in all_tab, the rest works correctly

2

u/SprinklesFresh5693 2d ago

This means that you probably have a list of objects in all , but that you cannot convert it directly to a dataframe due to not having the same rows.

My beleive is that your teacher wanted you to learn how to extract the relevant pueces from a list and turn them into dataframes for later reporting it in a formated table.

Try checking whats inside the all object and see what you need from there.b

1

u/Adventurous_Push_615 2d ago

On the extract function can you try raw = FALSE so it returns a data frame initially?

1

u/satvrtle 2d ago

it does not work, returns the error message : Error in .local(x, y, ...) : unused argument (row = FALSE)

1

u/Adventurous_Push_615 2d ago

raw not row...

1

u/Adventurous_Push_615 2d ago

Ah also, it's perhaps that worldclim_country is returning a list, data for each country and they have different numbers of rows - examine what it returns 

1

u/satvrtle 2d ago

yeah it's telling me that it's the class is a SpatRasterCollection. And yeah the nrows (and ncol) are all different indeed