清理混合地理数据 (R)
Cleaning Mixed Geographic Data (R)
我在一个包含州和城市(国内和国际)混合的数据集中有一个非常难看的列。其余数据都是数字,与地理无关。有没有什么方法可以进行文本分析以确定最终目标是什么,最终目标是将列分隔为州和城市,并在第三列中显示国家/地区?
c("Arizona", "(not set)", "Arizona", "(not set)", "California",
"California", "New York", "Texas", "New York", "Texas", "England",
"Illinois", "Florida", "Maharashtra", "Massachusetts", "Virginia",
"Maryland", "Florida", "Karnataka", "Pennsylvania", "Arizona",
"New Jersey", "Illinois", "District of Columbia", "Delhi", "Ohio",
"Ontario", "Georgia", "Colorado", "Washington", "Michigan", "Virginia",
"North Carolina", "England", "Maryland", "Pennsylvania", "Colorado",
"Utah", "Arizona", "New Jersey", "District of Columbia", "Tamil Nadu",
"North Carolina", "Arizona", "Massachusetts", "Tokyo", "Andhra Pradesh",
"Minnesota", "Washington", "Tainan City", "Michigan", "Arizona",
"Maharashtra", "Federal District", "Ile-de-France", "Utah", "Georgia",
"Metro Manila", "Ontario", "Connecticut")
根据您想要搜索的详尽程度,您可以下载 https://download.geonames.org/export/dump/ 下的一个或多个文件并搜索一列或多列。对于您提供的一组测试数据,我能够做到这一点:
temp <- tempfile()
download.file("https://download.geonames.org/export/dump/cities500.zip",temp)
unzipped <- unz(temp, "cities500.txt")
cities500 <- read.delim(unzipped, header=FALSE)
c("Arizona", "(not set)", "Arizona", "(not set)", "California",
"California", "New York", "Texas", "New York", "Texas", "England",
"Illinois", "Florida", "Maharashtra", "Massachusetts", "Virginia",
"Maryland", "Florida", "Karnataka", "Pennsylvania", "Arizona",
"New Jersey", "Illinois", "District of Columbia", "Delhi", "Ohio",
"Ontario", "Georgia", "Colorado", "Washington", "Michigan", "Virginia",
"North Carolina", "England", "Maryland", "Pennsylvania", "Colorado",
"Utah", "Arizona", "New Jersey", "District of Columbia", "Tamil Nadu",
"North Carolina", "Arizona", "Massachusetts", "Tokyo", "Andhra Pradesh",
"Minnesota", "Washington", "Tainan City", "Michigan", "Arizona",
"Maharashtra", "Federal District", "Ile-de-France", "Utah", "Georgia",
"Metro Manila", "Ontario", "Connecticut") %in% cities500$V2
请注意,我并未对您的输入进行详尽测试,只是为了展示各种可能性。由于站点中有多个转储文件,每个转储文件中有多个列,您需要进行试验并找到合适的文件。
我在一个包含州和城市(国内和国际)混合的数据集中有一个非常难看的列。其余数据都是数字,与地理无关。有没有什么方法可以进行文本分析以确定最终目标是什么,最终目标是将列分隔为州和城市,并在第三列中显示国家/地区?
c("Arizona", "(not set)", "Arizona", "(not set)", "California",
"California", "New York", "Texas", "New York", "Texas", "England",
"Illinois", "Florida", "Maharashtra", "Massachusetts", "Virginia",
"Maryland", "Florida", "Karnataka", "Pennsylvania", "Arizona",
"New Jersey", "Illinois", "District of Columbia", "Delhi", "Ohio",
"Ontario", "Georgia", "Colorado", "Washington", "Michigan", "Virginia",
"North Carolina", "England", "Maryland", "Pennsylvania", "Colorado",
"Utah", "Arizona", "New Jersey", "District of Columbia", "Tamil Nadu",
"North Carolina", "Arizona", "Massachusetts", "Tokyo", "Andhra Pradesh",
"Minnesota", "Washington", "Tainan City", "Michigan", "Arizona",
"Maharashtra", "Federal District", "Ile-de-France", "Utah", "Georgia",
"Metro Manila", "Ontario", "Connecticut")
根据您想要搜索的详尽程度,您可以下载 https://download.geonames.org/export/dump/ 下的一个或多个文件并搜索一列或多列。对于您提供的一组测试数据,我能够做到这一点:
temp <- tempfile()
download.file("https://download.geonames.org/export/dump/cities500.zip",temp)
unzipped <- unz(temp, "cities500.txt")
cities500 <- read.delim(unzipped, header=FALSE)
c("Arizona", "(not set)", "Arizona", "(not set)", "California",
"California", "New York", "Texas", "New York", "Texas", "England",
"Illinois", "Florida", "Maharashtra", "Massachusetts", "Virginia",
"Maryland", "Florida", "Karnataka", "Pennsylvania", "Arizona",
"New Jersey", "Illinois", "District of Columbia", "Delhi", "Ohio",
"Ontario", "Georgia", "Colorado", "Washington", "Michigan", "Virginia",
"North Carolina", "England", "Maryland", "Pennsylvania", "Colorado",
"Utah", "Arizona", "New Jersey", "District of Columbia", "Tamil Nadu",
"North Carolina", "Arizona", "Massachusetts", "Tokyo", "Andhra Pradesh",
"Minnesota", "Washington", "Tainan City", "Michigan", "Arizona",
"Maharashtra", "Federal District", "Ile-de-France", "Utah", "Georgia",
"Metro Manila", "Ontario", "Connecticut") %in% cities500$V2
请注意,我并未对您的输入进行详尽测试,只是为了展示各种可能性。由于站点中有多个转储文件,每个转储文件中有多个列,您需要进行试验并找到合适的文件。