Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help Please: I get this error: Error in .subset2(x, i, exact = exact) : attempt to select less than one element in get1index #32

Open
tosinaregbs2 opened this issue Mar 4, 2024 · 4 comments

Comments

@tosinaregbs2
Copy link

I am new to SDM and also using spThin package. I have this line of code:
##############################################################################
#Clean up!
rm(list=ls())

load the required packages

library(spThin)

read data ----

species occurrences data

DataSpecies <- read.csv("C:/Users/tosin/OneDrive/Documents/SDM proo/AspilaAfricana1.csv", stringsAsFactors = FALSE)
head(DataSpecies)

Select the name of the studied species

myRespName <- 'Aspiliaafricana'

Get corresponding presence/absence data

myResp <- as.numeric(DataSpecies[, myRespName])

Get corresponding XY coordinates

myRespXY_pre <- DataSpecies[, c('X_WGS84', 'Y_WGS84')]
#Remove NAs
acgeo <- subset(myRespXY_pre, !is.na(X_WGS84) & !is.na(Y_WGS84))

Define thinning parameters

thin_par <- 0.5
reps <- 10

Thin the data

thinned_data <- thin(
loc.data = acgeo,
lat.col = "Y_WGS84",
long.col = "X_WGS84",
spec.col = "myRespName",
thin.par = thin_par,
reps = reps,
write.files = TRUE,
out.base = "thinned_data_",
verbose = TRUE
)

Print information about the thinned data

print(thinned_data)

#############################################################################

head(DataSpecies)
Aspiliaafricana country Code X_WGS84 Y_WGS84
1 1 BJ 6.650 2.600
2 1 BJ 9.100 1.933
3 1 BJ 6.416 2.616
4 1 BJ 9.350 1.400
5 1 BJ 6.883 1.600
6 1 BJ 9.350 1.450
##############################################################################
I get this error:
Beginning Spatial Thinning. Script Started at: Mon Mar 4 09:55:26 2024Error in .subset2(x, i, exact = exact) : attempt to select less than one element in get1index

Can anyone help with guidiance on how to resolve it

@mlammens
Copy link
Owner

mlammens commented Mar 6, 2024

Hi @tosinaregbs2 , it looks to me like the problem is coming from how your are defining your species column. As I see it here, it looks like you've created a column titled Aspiliaafricana, and then forced the elements of that column to be numbers.

@tosinaregbs2
Copy link
Author

tosinaregbs2 commented Mar 6, 2024

Hi @mlammens, I have replaced the numbers in the species column with the species name and also tried suggestions from previous from your responses to similar questions. One of the suggestion is to convert to degrees. I have converted to degrees (to be sure it is). I also varied the thin.par., but the error persists. Thanks for your support.

head(DataSpecies)
Aspiliaafricana countryCode X_WGS84 Y_WGS84
1 Aafricana BJ 6.650 2.600
2 Aafricana BJ 9.100 1.933
3 Aafricana BJ 6.416 2.616
4 Aafricana BJ 9.350 1.400
5 Aafricana BJ 6.883 1.600
6 Aafricana BJ 9.350 1.450

@mlammens
Copy link
Owner

mlammens commented Mar 7, 2024

@tosinaregbs2 , try running the thin function with the spec.col column set to Aspiliaafricana and let me know what happens.

@tosinaregbs2
Copy link
Author

Hi @mlammens I just replaced the spec.col column with Aspiliaafricana and it still brings back the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants