从R中的列表中提取sf对象的名称

cclgggtu  于 2023-01-28  发布在  其他
关注(0)|答案(1)|浏览(170)

我试图提取列表中对象的名称,它们都是sf。所以我不能使用名称。

`subte_estaciones <- st_read("http://bitsandbricks.github.io/data/subte_estaciones.geojson")

Universidades = read.csv("C:/Users/sixto/OneDrive/Documentos/GCBA/Alquiler Social/Universidades.csv")
Universidades <- Universidades %>%  st_as_sf(coords = c("long", "lat"), crs = 4326)

trenes = st_read("https://cdn.buenosaires.gob.ar/datosabiertos/datasets/transporte-y-obras-publicas/estaciones-ferrocarril/estaciones-de-ferrocarril.geojson")

object_list = list(subte_estaciones , trenes , Universidades  )  

names(object_list)


我需要一个向量中的对象名称来替换列名。
我几乎什么都试过了,但都无济于事。
对象名称〈- c()

# Use a for loop to iterate through the list and store the names of the objects in the new vector
for(i in 1:length(object_list)) {
    object_names[i] <- paste0(deparse(substitute(object_list[[i]])),i)
}
# Print the new vector of object names
object_names

# Create a new vector to store the names of the sf objects
object_names <- c()

# Use a for loop to iterate through the list and store the names of the objects in the new vector
for(i in 1:length(object_list)) {
    object_names[i] <- paste0("sf_object_",i)
}

# Print the new vector of object names
object_names
syqv5f0l

syqv5f0l1#

要获取object_list的名称,必须首先命名列表中的对象

object_list= list(subte_estaciones = subte_estaciones,trenes = trenes, Universidades = Universidades)
names = names(object_list)
names
[1] "subte_estaciones" "Universidades"    "trenes"

相关问题