R语言提取经纬度 - 示例代码
{"title":"R语言提取经纬度 - 示例代码","description":"本文提供使用R语言从文本中提取经纬度的代码示例,并解释了代码的逻辑和使用方法。","keywords":"R语言, 经纬度, 提取, 代码, 示例, 文本处理, 字符串处理","content":""Location: Latitude 25.9429 Longitude -80.8048 "\n写一段R语言的代码,分别按照"Latitude"和"Longitude"提取上面文本中的经纬度内容:以下是使用R语言提取经纬度的代码:\n\nR\n# 原始文本\ntext <- \"Location: Latitude 25.9429 Longitude -80.8048\"\n\n# 提取经度\nlongitude <- as.numeric(sub(\".*Longitude\s*(-?\d+\.\d+).*\", \"\1\", text))\nprint(longitude)\n\n# 提取纬度\nlatitude <- as.numeric(sub(\".*Latitude\s*(-?\d+\.\d+).*\", \"\1\", text))\nprint(latitude)\n\n\n输出结果:\n\n\n[1] -80.8048\n[1] 25.9429\n
原文地址: https://www.cveoy.top/t/topic/pPPX 著作权归作者所有。请勿转载和采集!