Extracting specific data from an RData file

夙愿已清 提交于 2019-12-13 02:36:44

问题


I ask to be excused for my ignorance of R which I have been learning for the past one month. Specifically I have downloaded xxx_adm-_RData files (xxx for the country and - being 0, 1 or 2) for a number of countries of interest. My real interest are just the long/lat coordinates of each country, which I can use to overlay on analyses of climate fields like rainfall, temperature, etc. For the past two weeks I have been going through SO posts on how I can access a country's coordinates in an RData file and use them with other data, without any success. My attempts to get google maps or readGR() or readBin() after a download have not been successful. I wonder whether what am asking for is feasible.


回答1:


after putting the rdata file in your working directory, do something like

load("C:/Users/1_adm.RData", ex <- new.env())
ls.str(ex)

The rdata loads variable into your workspace so that command will show you what the variable names are, so you can then use them.

I don't have the file you're talking about so I can't tell you how to access the specific fields you need.

edit

Based on your comment: Ok so the object you load is an object of type SpatialPolygonsDataFrame, and that has a Slot/property called Polygons, with objects of type Polygon. Those polygons I assume are the lat lng coordinates around the country. Accessing the coordinates should look something like

ps <- gadm@polygons[1]   

then something like

ps@coords  


来源:https://stackoverflow.com/questions/19575085/extracting-specific-data-from-an-rdata-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!