Reading an ASC file into R

前端 未结 4 751
后悔当初
后悔当初 2021-02-18 19:11

I\'m currently trying to extract information from various \"ASC\" files into R in order to perform analysis on the data.

The issue is that I am unsure of how exactly to

相关标签:
4条回答
  • 2021-02-18 19:25

    Package SDMTools has the function read.asc, which works under R 3.2.4. However, at least in my case, using read.table with all default values worked out of the box.

    0 讨论(0)
  • 2021-02-18 19:30

    I used the command x =read.csv("C:\...\Dropbox/MVZ//aet2009sep.asc", sep=";")

    I found this after using the importing manually with the import button in the Environment window.

    0 讨论(0)
  • 2021-02-18 19:35

    Update: It is possible to read .asc files (aka ESRI ASCII Raster files) with the raster function directly from the 'raster' package. The help says:

    If x is a filename, the following additional variables are recognized:

    native: logical. Default is FALSE except when package rgdal is missing. If TRUE, reading and writing of ..., and Arc ASCII files is done with native (raster package) drivers, rather than via rgdal....

    library(raster)
    r = raster("C:\\...\\Dropbox/MVZ/aet2009sep.asc")
    plot(r)
    

    Edit 2 [obsolete]:

    An alternative is the raster() function, having the package rgdal properly installed.

    library(rgdal)
    r = raster("C:\\...\\Dropbox/MVZ/aet2009sep.asc")
    plot(r)
    

    Edit 1 [obsolete]:

    The package adehabitat is now deprecated. Currently, it provides a warning when loading it:

    It is dangerous to use it, as bugs will no longer be corrected. It is now recommended to use the packages adehabitatMA, adehabitatLT, adehabitatHR, and adehabitatHS.
    ...

    Original answer [obsolete]:

    Use the import.asc function from R package adehabitat (see page 92):

    library(adehabitat)
    asc = import.asc("C:\\...\\Dropbox/MVZ/aet2009sep.asc")
    
    #plot asc object.
    library(raster)
    r = raster(asc)
    plot(r)
    
    0 讨论(0)
  • 2021-02-18 19:48

    Use Laf package, it is insanely fast.

    0 讨论(0)
提交回复
热议问题