Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7720545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:42:10+00:00 2026-06-01T03:42:10+00:00

I have a datset, which is dat<-matrix(seq(1:5290),c(115,46)) How can I convert dat to a

  • 0

I have a datset, which is

dat<-matrix(seq(1:5290),c(115,46))
  1. How can I convert dat to a raster file with GIS – related metadata such as map projection?
  2. and then how to map the data to a us map with

    lon <- seq(-124.25,length=115,by=0.5)    
    lat <- seq(26.25,length=46,by=0.5)
    
  3. what should I do if I want to calculate the mean of each state? or specific region?

thanks very much for your feedback.

D

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:42:12+00:00Added an answer on June 1, 2026 at 3:42 am

    You could try the following:

    library(raster)
    library(maps)
    
    dat<-matrix(seq(1:5290),c(115,46))  
    

    Create a raster with your desired extent

    r <- raster(dat)
    e <- extent(c(-124.5, -67.25, 26.25, 48.75))
    extent(r) <- e
    

    and plot it

    plot(r)
    map("usa", add=T)
    

    take the mean over the whole raster

    mean(getValues(r))
    

    mean over a region

    r.sub <- crop(r, c(-100, -54, 40, 45))
    mean(getValues(r.sub))
    

    Extract from polygons

    You need a SpatialPolygonsDataFrame. Here I am creating a dummy one with readWKT() but you could also read a shapefile with readShapePoly() from the maptools package.

    library(rgeos)
    poly <- readWKT("POLYGON((-100 30, -100 31, -70 30, -88 29, -100 30))")
    plot(r)
    plot(poly, add=T)
    

    And extract the mean:

    dat <- extract(r, poly)
    sapply(dat, mean)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data set, dat, which was got from a model run. The
I have DataSet which has 3 columns. Name - insurance comp. name - treatmentDate
(Using Visual Studio 2005 / .NET 2.0) I have a DataSet which is being
I have created a dataset in my visual studio project which is connected to
I have a moderately sized dataset in excel from which I wish to extract
Scenario I have a DevExpress DataGrid which is bound to a DataSet in C#.
I have a (disconnected) typed Dataset in an XML, which I query in LINQ:
I have the following sample dataset (below and/or as CSVs here: http://goo.gl/wK57T ) which
I have a UltraWinGrid that is bound to a DataSet, in which a couple
I have a dataset which I want to use as a parameter for my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.