简体   繁体   English

如何从 rgbif 中的搜索中保存出现数据

[英]How to save occurrence data from a search in rgbif

I am a new R user and I am interested in downloading a particular set of data using rgbif.我是一个新的 R 用户,我有兴趣使用 rgbif 下载一组特定的数据。 I did:我做了:

occ_search(scientificName = "Lupinus", hasCoordinate = TRUE, continent = c('africa', 'europe', 'asia'),
       basisOfRecord = "PRESERVED_SPECIMEN", decimalLatitude = '-1.50750278, 47.62390556',
       decimalLongitude = '-18.75250000, 52.85138889',
       fields = c('scientificName', 'decimalLatitude', 'decimalLongitude', 'country'), return = 'data')

Which works fine to do the search.这可以很好地进行搜索。 However, what I would like to do is save the search as an object to create an .csv file of it.但是,我想要做的是将搜索保存为一个对象,以创建它的 .csv 文件。 If I go:如果我走:

OS <- occ_search(scientificName = "Lupinus", hasCoordinate = TRUE, continent = c('africa', 'europe', 'asia'),
       basisOfRecord = "PRESERVED_SPECIMEN", decimalLatitude = '-1.50750278, 47.62390556',
       decimalLongitude = '-18.75250000, 52.85138889',
       fields = c('scientificName', 'decimalLatitude', 'decimalLongitude', 'country'), return = 'data')

Then然后

OS1 <- as.data.frame(OS)

I get the following error:我收到以下错误:

Error in as.data.frame.default(occ) : cannot coerce class ""gbif"" to a data.frame

I also tried using occ_download this way:我也试过这样使用occ_download

OD <- occ_download("scientificName = Lupinus",
                       "hasCoordinate = TRUE",
                       "continent = africa,europe,asia",
                       "basisOfRecord = PRESERVED_SPECIMEN",
                       "decimalLatitude >= -1.50750278", 
                       "decimalLatitude <= 47.62390556",
                       "decimalLongitude >= -18.75250000",
                       "decimalLongitude <= 52.85138889")                        

And all I get is a file with 0 observations and 235 columns.我得到的只是一个包含 0 个观察值和 235 列的文件。

Any help will be highly appreciated!任何帮助将不胜感激!

The reason your occ_search output is not compatible with as.data.frame is in the continent = c('africa', 'europe', 'asia') argument.您的occ_search输出与as.data.frame不兼容的原因是在continent = c('africa', 'europe', 'asia')参数中。 If you look at the length(OS) and str(OS) , you will see that it actually has three data.frames in it.如果您查看length(OS)str(OS) ,您会发现它实际上包含三个 data.frames。 You can access the individual elements like this:您可以像这样访问各个元素:

OS$europe
# or
OS['europe']
# or
OS[[1]]

You can combine these like this你可以像这样组合这些

OC1 <- rbind(OS$africa, OS$europe, OS$asia)

Or, if you are not going to know all the different names, like this:或者,如果您不打算知道所有不同的名称,如下所示:

do.call(rbind, OS)

To transform the object with class "gbif" to a data.frame you can do OS.df <- do.call(rbind.data.frame, OS) .要将具有class "gbif"的对象转换为 data.frame,您可以执行OS.df <- do.call(rbind.data.frame, OS)

For occ_download you need to set a username, email and password.对于occ_download您需要设置用户名、电子邮件和密码。 As by gbif website (http://www.gbif.org/developer/occurrence#download) Occurrence downloads are created asynchronously - the user requests a download and, once complete, is sent and email with a link to the resulting file.正如 gbif 网站(http://www.gbif.org/developer/occurrence#download) 一样,事件下载是异步创建的 - 用户请求下载,一旦完成,就会发送并通过电子邮件发送结果文件的链接。

OD <- occ_download(user = "name", pwd = "pass", email = "e@mail.com", "scientificName = Lupinus", "hasCoordinate = TRUE", "continent = africa,europe,asia","basisOfRecord = PRESERVED_SPECIMEN","decimalLatitude >= -1.50750278","decimalLatitude <= 47.62390556","decimalLongitude >= -18.75250000","decimalLongitude <= 52.85138889")

returns an object of class gbif download and you should receive a download link per mail or visit http://www.gbif.org/user/download to download directly.返回类gbif download的对象,您应该会收到每封邮件的下载链接或访问http://www.gbif.org/user/download直接下载。 This can be done through the download option at gbif.org as well.这也可以通过gbif.org 上的下载选项来完成。

<<gbif download>> Username: philipprobeck E-mail: phill@gmx.li Download key: 0078579-160910150852091

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何保存通过rgbif下载的单个物种数据? - How do I save individual species data downloaded via rgbif? 无法使用 R 中 rgbif 包的 occ_search 函数获取出现数据 - Unable to fetch Occurrence Data using occ_search function of rgbif package in R 如何从此列表(从rgbif)中提取值并将其转换为R中的数据帧? - How extract values from this list (from rgbif) and convert it in data frame in R? 将库(rgbif)函数occ_data中的列表拆分为数据帧 - split lists from library(rgbif) function occ_data into data frame 如何计算R中数据集中排列的出现次数? - How to count the occurrence of permutations in a data set in R? 如何使用R从具有多列的数据框中计算(共)发生矩阵? - How to calculate a (co-)occurrence matrix from a data frame with several columns using R? 如何汇总数据框中的行并保留分组变量第二次出现的字符值? - How can I summarize rows in a data frame and keep the character values from the second occurrence of the grouping variable? 如何在R中的数据帧中找到一列中出现字符串最长的时间以及另一列中对应的第一个和最后一个值? - How to find the longest occurrence of a string in a column and corresponding first and last values from another column in a data frame in R? 使发生数据和气候栅格中的 SpatialGridDataFrame 相互匹配 - Make SpatialGridDataFrame from occurrence data and climate raster match each other 无法在R中安装rgbif软件包 - Trouble installing rgbif package in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM