I am trying to use coordinates function from sp package to transform my data in spatial data. I made sure I deleted all the NAs values and that all my data is numeric, however, i still get the same error. I have checked in the package information about negative values, but it seems should not be the problem
require(adegenet)
require(pegas)
require(sp)
require(PopGenReport)
require(dplyr)
require(poppr)
Sites.sp <- Locations
SitesNA.sp<-subset(Sites.sp,!(is.na(Sites.sp["Latitude"]) |
is.na(Sites.sp["Longitude"])))
coordinates(SitesNA.sp) <- ~Latitude+Longitude
as.tibble(SitesNA.sp)
coordinates(SitesNA.sp) <- ~Latitude+Longitude Error in .local(obj, ...) : cannot derive coordinates from non-numeric matrix
dput
structure(list(
A/A= c(NA, NA, 174, 173, 164, 152), YEAR = c("2016", "2016", "2014", "2014", "2013", NA), Collector = c("P. Carazo", "P. Carazo", "AubretTeam", "AubretTeam", "UllerTeam", "AubretTeam" ), Population = c("Istria, Pula", "Cres Island, Cres Township", "Ile d'Yeu Saint-sauveur", "Ile d'Yeu Port Joinville", "Vitre", "Taurignan Vieux"), Country = c("Croatia", "Croatia", "FR", "FR", "FR", "FR"), Abbreviation = c("Pula", "Cres Township", "YSS", "YPJ", "VR", "TV"), Latitude = c("44.849504000000003", "44.959245000000003", "46.706412999999998", "46.727950499999999", "48.124009999999998", "43.0276"), Longitude = c("13.849347", "14.404019999999999", "-2.3309148999999998", "-2.3523725999999998", "-1.2143999999999999", "1.1152"), Altitude = c(NA, NA, "NA", "NA", "91", "NA"), No.Samples = c("3", "3", "34", "No samples sent", "20", "30"), X__1 = c(NA, NA, NA, NA, "Geoff to confirm exact location", NA)), .Names = c("A/A", "YEAR", "Collector", "Population", "Country", "Abbreviation", "Latitude", "Longitude", "Altitude", "No.Samples", "X__1"), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"))
SitesNA
is not the same thanSitesNA.sp
. This kind of code isn't object-oriented, so.sp
is not an attribute or method ofSitesNA
dput(head(SitesNA))
to trying to reproduce the problem?