搜索了很多,没有找到回复。
我正在为 qdap 库中的“查找”功能而苦苦挣扎。我在数据框 CityCountry 中有一个城市名称列表;这是代码和str:
CityCountry <- data.frame(City = as.character(rownames(spint)))
CityCountry <- as.character(CityCountry)
str(CityCountry)
chr "c(18, 40, 55, 64, 68, 70, 82, 86, 90, 107, 121, 127, 144, 152, 163, 184, 194, 205, 210, 211, 213, 217, 218, 223, 226, 227, 228,"| __truncated__
spint 是一个最短路径数据框,它使用相关城市名称作为行名。我想抓住这些,用它们新建一个数据框,在数据框routes_lookup中查找每个城市对应的国家。这是 str(routes_lookup) 和我的查找函数:
str(routes_lookup)
'data.frame': 2792 obs. of 2 variables:
$ City_Dest : chr "Buenos Aires" "Buenos Aires" "Mar Del Plata" "Mar Del Plata" ...
$ Country_Dest: Factor w/ 240 levels "Afghanistan",..: 9 9 9 9 9 9 9 152 152 170 ...
CityCountry$Country <- lookup(CityCountry, routes_lookup)
这是我不断收到的错误。我已经尝试过很多次,但上面的函数调用似乎最接近正确(尽管当然不完全在那里)。
Error in exists(x, envir = envr) :
variable names are limited to 10000 bytes
我当然认为上面显示的 str(CityCountry) 说明了这个问题。但是数据框包含 chr 类型的列,routes_lookup 中的 City_Dest 列也是如此。如何使这两列具有相同的数据类型?