Hi!
I have been trying to create a hypervolume using climatic data and species data. The data itself is ready, but I am encountering problems when building the hypervolume, especifically when selecting the climatic variables and single species I want to use. I have properly installed and loaded the Tidyverse package, but I can't seem to be able to get it to work. Here is my code (including all my different attempts and errors):
hv1 <- hypervolume(df.clim.occ_wider %>% filter(., "species" == "Celtis australis") %>% select(mean_temperature, mean_precipitation, seasonality_temperature, seasonilty_precipitation)) #Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘select’ for signature ‘"mts"’
hv1 <- hypervolume(df.clim.occ_wider %>% dplyr::select(., "species" == "Celtis australis") %>% select(mean_temperature, mean_precipitation, seasonality_temperature, seasonilty_precipitation))
error in evaluating the argument 'x' in selecting a method for function 'select': Must subset columns with a valid subscript vector
hv1 <- hypervolume(df.clim.occ_wider %>% select(., "species" == "Celtis australis") %>% select(mean_temperature, mean_precipitation, seasonality_temperature, seasonilty_precipitation))
error in evaluating the argument 'x' in selecting a method for function 'select': unable to find an inherited method for function ‘select’ for signature ‘"tbl_df"’
I have looked for especific information about the hzpervolume package but have not found anzthing helpful.
Thank you for your quick answer. I have checked with class() and it is indeed a data frame. I have tried using dplyr::select exclusively in the command line and get this error:
hv1 <- hypervolume(df.clim.occ_wider %>% dplyr::select(., "species" == "Celtis australis") %>% dplyr::select(mean_temperature, mean_precipitation, seasonality_temperature, seasonilty_precipitation))
Error in dplyr::select():
! Must subset columns with a valid subscript vector. Subscript has the wrong type logical. It must be numeric or character.
Run rlang::last_error() to see where the error occurred.
rlang::last_error()
<error/vctrs_error_subscript_type>
Error in dplyr::select():
! Must subset columns with a valid subscript vector. Subscript has the wrong type logical. It must be numeric or character.
Backtrace:
hypervolume::hypervolume(...)
rlang::cnd_signal(x)
Run rlang::last_trace() to see the full context.
Not sure what it means by this since the dataframe seems to be fine.
I wanted to select only the data from that especific plant species. I was trying to create one hypervolume per species, so first I had to select the species from my dataframe.
Good catch, and explains the error because species == something will return a TRUE or FALSE. One of the things that drives me nuts about dplyr is keeping select and filter straight: select is for columns and filter is for rows, which likes the typeof logical return value.
Most likely the filter is not quite matching the data and nothing is returned. Things like capitalisation and whitespace might explain, among other possibilities
hypervolume(dataCeltisaustralis)
Error in hypervolume(dataCeltisaustralis) :
Hypervolume cannot be computed with empty input data.
Curiouslz, deleting the dot in .,select caused another error, so I left it there just in case. I have checked the species name and all other variables and they are properly written, with all variables containing data in the table, so I am not sure where this empty input data could be comming from. Any other suggestions?
Ok, I have just checked and apparently ther eis no data in the table. 0 observations of 4 variables, so the data is not properly loaded. Any idea on how this could be fixed?