[英]How to fix error in non-numeric matrix in R
我有这个数据框:
structure(list(Nazwa = c("a", "b"), Miejscowosc = c("aaa", "bbb"
), KodPocztowy = c("09-520", "44-207"), Zainstalowano = c("2020-03-20 00:00:00.000",
"2019-02-27 00:00:00.000"), Szczytowa = c(9.14, 4.5), Latitude = c("52.550000",
"50.101860"), Longitude = c("19.700000", "18.546640")), row.names = c(NA,
-2L), class = c("tbl_df", "tbl", "data.frame"))
我从aaa.xlsx文件中读取了这些数据。
points <- read_xlsx(paste0("From/",qwerty,"/aaa.xlsx"))
然后我尝试使用代码:
points_sp <- SpatialPoints(points[,c(6,7)], CRS("+init=EPSG:4326"))
不幸的是,我收到一个错误:无法从非数字矩阵导出坐标 如何解决?
您只需要将字符串转换为数字,将tbl_df
转换为矩阵或普通数据框:
points$Latitude <- as.numeric(points$Latitude)
points$Longitude <- as.numeric(points$Longitude)
points_sp <- SpatialPoints(as.data.frame(points[,c(6,7)]), CRS("+init=EPSG:4326"))
points_sp
SpatialPoints:
# Latitude Longitude
# [1,] 52.55000 19.70000
# [2,] 50.10186 18.54664
# Coordinate Reference System (CRS) arguments: +proj=longlat +datum=WGS84 +no_defs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.