How to create gridded data

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to create gridded data

lily li
Hi R users,

I have a question about manipulating data. For example, I have DF1 as the
following, how to transform it to a gridded dataset DF2? In DF2, each value
Precip is an attribute of the corresponding grid cell. So DF2 is like a
spatial surface, and can be imported to ArcGIS. Thanks for your help.

DF1
latitude   longitude   Precip
45.5           110.5         3.2
45.5           111            5.0
45.5           111.5         1.8
45.5           112            2.0
46              110.5         6.1
46              111            4.5
46              111.5         7.8
46              112            5.5
...


DF2
6.1   4.5   7.8   5.5
3.2   5.0   1.8   2.0
...

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to create gridded data

Jim Lemon-4
Hi lily,
Something like this should work:

DF1<-read.table(text=
"latitude   longitude   Precip
45.5           110.5         3.2
45.5           111            5.0
45.5           111.5         1.8
45.5           112            2.0
46              110.5         6.1
46              111            4.5
46              111.5         7.8
46              112            5.5",
header=TRUE)
lats<-sort(unique(DF1$latitude),decreasing=TRUE)
lons<-sort(unique(DF1$longitude))
DF2<-matrix(NA,nrow=length(lats),ncol=length(lons))
rownames(DF2)<-lats
colnames(DF2)<-lons
nval<-dim(DF1)[1]
for(val in 1:nval) {
 row<-which(lats == DF1$latitude[val])
 col<-which(lons == DF1$longitude[val])
 DF2[row,col]<-DF1$Precip[val]
}

Jim

On Tue, Nov 13, 2018 at 6:22 PM lily li <[hidden email]> wrote:

>
> Hi R users,
>
> I have a question about manipulating data. For example, I have DF1 as the
> following, how to transform it to a gridded dataset DF2? In DF2, each value
> Precip is an attribute of the corresponding grid cell. So DF2 is like a
> spatial surface, and can be imported to ArcGIS. Thanks for your help.
>
> DF1
> latitude   longitude   Precip
> 45.5           110.5         3.2
> 45.5           111            5.0
> 45.5           111.5         1.8
> 45.5           112            2.0
> 46              110.5         6.1
> 46              111            4.5
> 46              111.5         7.8
> 46              112            5.5
> ...
>
>
> DF2
> 6.1   4.5   7.8   5.5
> 3.2   5.0   1.8   2.0
> ...
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to create gridded data

S Ellison-2
In reply to this post by lily li
You might take a look at the reshape package, which switches from 'long' to 'wide' formats and vice versa in a fairly flexible way.

S Ellison

> -----Original Message-----
> From: R-help [mailto:[hidden email]] On Behalf Of lily li
> Sent: 13 November 2018 07:22
> To: R mailing list
> Subject: [R] How to create gridded data
>
> Hi R users,
>
> I have a question about manipulating data. For example, I have DF1 as the
> following, how to transform it to a gridded dataset DF2? In DF2, each value
> Precip is an attribute of the corresponding grid cell. So DF2 is like a
> spatial surface, and can be imported to ArcGIS. Thanks for your help.
>
> DF1
> latitude   longitude   Precip
> 45.5           110.5         3.2
> 45.5           111            5.0
> 45.5           111.5         1.8
> 45.5           112            2.0
> 46              110.5         6.1
> 46              111            4.5
> 46              111.5         7.8
> 46              112            5.5
> ...
>
>
> DF2
> 6.1   4.5   7.8   5.5
> 3.2   5.0   1.8   2.0
> ...
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to create gridded data

Sarah Goslee
In reply to this post by lily li
If you want an actual spatial dataset, the best place to ask is R-sig-geo

R has substantial capabilities for dealing with gridded spatial data,
including in the sp, raster, and sf packages.

Here's one approach, creating a SpatialGridDataFrame, which can be
exported in any standard raster format using the rgdal package.

DF2 <- DF1
coordinates(DF2) <- ~longitude + latitude
gridded(DF2) <- TRUE
fullgrid(DF2) <- TRUE

I recommend Roger Bivand's excellent book:
https://www.springer.com/us/book/9781461476177

and there are abundant web tutorials.

Sarah
On Tue, Nov 13, 2018 at 2:22 AM lily li <[hidden email]> wrote:

>
> Hi R users,
>
> I have a question about manipulating data. For example, I have DF1 as the
> following, how to transform it to a gridded dataset DF2? In DF2, each value
> Precip is an attribute of the corresponding grid cell. So DF2 is like a
> spatial surface, and can be imported to ArcGIS. Thanks for your help.
>
> DF1
> latitude   longitude   Precip
> 45.5           110.5         3.2
> 45.5           111            5.0
> 45.5           111.5         1.8
> 45.5           112            2.0
> 46              110.5         6.1
> 46              111            4.5
> 46              111.5         7.8
> 46              112            5.5
> ...
>
>
> DF2
> 6.1   4.5   7.8   5.5
> 3.2   5.0   1.8   2.0
> ...
>


--
Sarah Goslee (she/her)
http://www.numberwright.com

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to create gridded data

David Carlson
Sarah's answer is probably better depending on what you want to do with the resulting data, but here's a way to go from your original DF1 to DF2:

> DF1 <- structure(list(latitude = c(45.5, 45.5, 45.5, 45.5, 46, 46, 46,
+         46), longitude = c(110.5, 111, 111.5, 112, 110.5, 111, 111.5,
+         112), Precip = c(3.2, 5, 1.8, 2, 6.1, 4.5, 7.8, 5.5)),
+         class = "data.frame", row.names = c(NA, -8L))
>
# Convert to table with xtabs()
> DF2 <- xtabs(Precip~latitude+longitude, DF1)
>

# Reverse the order of the latitudes
> DF2 <- DF2[rev(rownames(DF2)), ]
> DF2
        longitude
latitude 110.5 111 111.5 112
    46     6.1 4.5   7.8 5.5
    45.5   3.2 5.0   1.8 2.0

# Convert to a data frame
> DF2 <- as.data.frame.matrix(DF2)
> DF2
     110.5 111 111.5 112
46     6.1 4.5   7.8 5.5
45.5   3.2 5.0   1.8 2.0

----------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352


-----Original Message-----
From: R-help <[hidden email]> On Behalf Of Sarah Goslee
Sent: Tuesday, November 13, 2018 8:16 AM
To: lily li <[hidden email]>
Cc: r-help <[hidden email]>
Subject: Re: [R] How to create gridded data

If you want an actual spatial dataset, the best place to ask is R-sig-geo

R has substantial capabilities for dealing with gridded spatial data,
including in the sp, raster, and sf packages.

Here's one approach, creating a SpatialGridDataFrame, which can be
exported in any standard raster format using the rgdal package.

DF2 <- DF1
coordinates(DF2) <- ~longitude + latitude
gridded(DF2) <- TRUE
fullgrid(DF2) <- TRUE

I recommend Roger Bivand's excellent book:
https://www.springer.com/us/book/9781461476177

and there are abundant web tutorials.

Sarah
On Tue, Nov 13, 2018 at 2:22 AM lily li <[hidden email]> wrote:

>
> Hi R users,
>
> I have a question about manipulating data. For example, I have DF1 as the
> following, how to transform it to a gridded dataset DF2? In DF2, each value
> Precip is an attribute of the corresponding grid cell. So DF2 is like a
> spatial surface, and can be imported to ArcGIS. Thanks for your help.
>
> DF1
> latitude   longitude   Precip
> 45.5           110.5         3.2
> 45.5           111            5.0
> 45.5           111.5         1.8
> 45.5           112            2.0
> 46              110.5         6.1
> 46              111            4.5
> 46              111.5         7.8
> 46              112            5.5
> ...
>
>
> DF2
> 6.1   4.5   7.8   5.5
> 3.2   5.0   1.8   2.0
> ...
>


--
Sarah Goslee (she/her)
http://www.numberwright.com

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to create gridded data

lily li
Thanks, Sarah's answer helps the question. Now how to change the gridded
data back to DF1 format? I don't know how to name the format, thanks.

On Tue, Nov 13, 2018 at 10:56 PM David L Carlson <[hidden email]> wrote:

> Sarah's answer is probably better depending on what you want to do with
> the resulting data, but here's a way to go from your original DF1 to DF2:
>
> > DF1 <- structure(list(latitude = c(45.5, 45.5, 45.5, 45.5, 46, 46, 46,
> +         46), longitude = c(110.5, 111, 111.5, 112, 110.5, 111, 111.5,
> +         112), Precip = c(3.2, 5, 1.8, 2, 6.1, 4.5, 7.8, 5.5)),
> +         class = "data.frame", row.names = c(NA, -8L))
> >
> # Convert to table with xtabs()
> > DF2 <- xtabs(Precip~latitude+longitude, DF1)
> >
>
> # Reverse the order of the latitudes
> > DF2 <- DF2[rev(rownames(DF2)), ]
> > DF2
>         longitude
> latitude 110.5 111 111.5 112
>     46     6.1 4.5   7.8 5.5
>     45.5   3.2 5.0   1.8 2.0
>
> # Convert to a data frame
> > DF2 <- as.data.frame.matrix(DF2)
> > DF2
>      110.5 111 111.5 112
> 46     6.1 4.5   7.8 5.5
> 45.5   3.2 5.0   1.8 2.0
>
> ----------------------------------------
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>
>
> -----Original Message-----
> From: R-help <[hidden email]> On Behalf Of Sarah Goslee
> Sent: Tuesday, November 13, 2018 8:16 AM
> To: lily li <[hidden email]>
> Cc: r-help <[hidden email]>
> Subject: Re: [R] How to create gridded data
>
> If you want an actual spatial dataset, the best place to ask is R-sig-geo
>
> R has substantial capabilities for dealing with gridded spatial data,
> including in the sp, raster, and sf packages.
>
> Here's one approach, creating a SpatialGridDataFrame, which can be
> exported in any standard raster format using the rgdal package.
>
> DF2 <- DF1
> coordinates(DF2) <- ~longitude + latitude
> gridded(DF2) <- TRUE
> fullgrid(DF2) <- TRUE
>
> I recommend Roger Bivand's excellent book:
> https://www.springer.com/us/book/9781461476177
>
> and there are abundant web tutorials.
>
> Sarah
> On Tue, Nov 13, 2018 at 2:22 AM lily li <[hidden email]> wrote:
> >
> > Hi R users,
> >
> > I have a question about manipulating data. For example, I have DF1 as the
> > following, how to transform it to a gridded dataset DF2? In DF2, each
> value
> > Precip is an attribute of the corresponding grid cell. So DF2 is like a
> > spatial surface, and can be imported to ArcGIS. Thanks for your help.
> >
> > DF1
> > latitude   longitude   Precip
> > 45.5           110.5         3.2
> > 45.5           111            5.0
> > 45.5           111.5         1.8
> > 45.5           112            2.0
> > 46              110.5         6.1
> > 46              111            4.5
> > 46              111.5         7.8
> > 46              112            5.5
> > ...
> >
> >
> > DF2
> > 6.1   4.5   7.8   5.5
> > 3.2   5.0   1.8   2.0
> > ...
> >
>
>
> --
> Sarah Goslee (she/her)
> http://www.numberwright.com
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to create gridded data

R help mailing list-2
Sarah's answer is probably the best approach, but to do it using very basic R methods that predate the very good spatial support that R now has, I would likely do this:

## Thanks, Jim Lemon, for this step:
df1 <- read.table(text=
"latitude   longitude   Precip
45.5           110.5         3.2
45.5           111            5.0
45.5           111.5         1.8
45.5           112            2.0
46              110.5         6.1
46              111            4.5
46              111.5         7.8
46              112            5.5",
header=TRUE)

## first sort
df1 <- df1[order(df1$latitude, df1$longitude) , ]

## convert vector of precipitations to matrix
df2 <- matrix(df1$Precip, nrow=length(unique(df1$latitude)), byrow=TRUE)

## reorder the latitudes (rows)
df2 <- df2[ nrow(df2):1 , ]

## > df2
##      [,1] [,2] [,3] [,4]
## [1,]  6.1  4.5  7.8  5.5
## [2,]  3.2  5.0  1.8  2.0

## From the original question:
## DF2
## 6.1   4.5   7.8   5.5
## 3.2   5.0   1.8   2.0
## ...

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 11/13/18, 8:50 PM, "R-help on behalf of lily li" <[hidden email] on behalf of [hidden email]> wrote:

    Thanks, Sarah's answer helps the question. Now how to change the gridded
    data back to DF1 format? I don't know how to name the format, thanks.
   
    On Tue, Nov 13, 2018 at 10:56 PM David L Carlson <[hidden email]> wrote:
   
    > Sarah's answer is probably better depending on what you want to do with
    > the resulting data, but here's a way to go from your original DF1 to DF2:
    >
    > > DF1 <- structure(list(latitude = c(45.5, 45.5, 45.5, 45.5, 46, 46, 46,
    > +         46), longitude = c(110.5, 111, 111.5, 112, 110.5, 111, 111.5,
    > +         112), Precip = c(3.2, 5, 1.8, 2, 6.1, 4.5, 7.8, 5.5)),
    > +         class = "data.frame", row.names = c(NA, -8L))
    > >
    > # Convert to table with xtabs()
    > > DF2 <- xtabs(Precip~latitude+longitude, DF1)
    > >
    >
    > # Reverse the order of the latitudes
    > > DF2 <- DF2[rev(rownames(DF2)), ]
    > > DF2
    >         longitude
    > latitude 110.5 111 111.5 112
    >     46     6.1 4.5   7.8 5.5
    >     45.5   3.2 5.0   1.8 2.0
    >
    > # Convert to a data frame
    > > DF2 <- as.data.frame.matrix(DF2)
    > > DF2
    >      110.5 111 111.5 112
    > 46     6.1 4.5   7.8 5.5
    > 45.5   3.2 5.0   1.8 2.0
    >
    > ----------------------------------------
    > David L Carlson
    > Department of Anthropology
    > Texas A&M University
    > College Station, TX 77843-4352
    >
    >
    > -----Original Message-----
    > From: R-help <[hidden email]> On Behalf Of Sarah Goslee
    > Sent: Tuesday, November 13, 2018 8:16 AM
    > To: lily li <[hidden email]>
    > Cc: r-help <[hidden email]>
    > Subject: Re: [R] How to create gridded data
    >
    > If you want an actual spatial dataset, the best place to ask is R-sig-geo
    >
    > R has substantial capabilities for dealing with gridded spatial data,
    > including in the sp, raster, and sf packages.
    >
    > Here's one approach, creating a SpatialGridDataFrame, which can be
    > exported in any standard raster format using the rgdal package.
    >
    > DF2 <- DF1
    > coordinates(DF2) <- ~longitude + latitude
    > gridded(DF2) <- TRUE
    > fullgrid(DF2) <- TRUE
    >
    > I recommend Roger Bivand's excellent book:
    > https://www.springer.com/us/book/9781461476177
    >
    > and there are abundant web tutorials.
    >
    > Sarah
    > On Tue, Nov 13, 2018 at 2:22 AM lily li <[hidden email]> wrote:
    > >
    > > Hi R users,
    > >
    > > I have a question about manipulating data. For example, I have DF1 as the
    > > following, how to transform it to a gridded dataset DF2? In DF2, each
    > value
    > > Precip is an attribute of the corresponding grid cell. So DF2 is like a
    > > spatial surface, and can be imported to ArcGIS. Thanks for your help.
    > >
    > > DF1
    > > latitude   longitude   Precip
    > > 45.5           110.5         3.2
    > > 45.5           111            5.0
    > > 45.5           111.5         1.8
    > > 45.5           112            2.0
    > > 46              110.5         6.1
    > > 46              111            4.5
    > > 46              111.5         7.8
    > > 46              112            5.5
    > > ...
    > >
    > >
    > > DF2
    > > 6.1   4.5   7.8   5.5
    > > 3.2   5.0   1.8   2.0
    > > ...
    > >
    >
    >
    > --
    > Sarah Goslee (she/her)
    > http://www.numberwright.com
    >
    > ______________________________________________
    > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
    > https://stat.ethz.ch/mailman/listinfo/r-help
    > PLEASE do read the posting guide
    > http://www.R-project.org/posting-guide.html
    > and provide commented, minimal, self-contained, reproducible code.
    >
   
    [[alternative HTML version deleted]]
   
    ______________________________________________
    [hidden email] mailing list -- To UNSUBSCRIBE and more, see
    https://stat.ethz.ch/mailman/listinfo/r-help
    PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
    and provide commented, minimal, self-contained, reproducible code.
   

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to create gridded data

David Carlson
In reply to this post by lily li
It would depend on the format of the gridded data. Assuming it is a data frame like DF2 in my earlier answer, you just reverse the steps:

> DF2
     110.5 111 111.5 112
46     6.1 4.5   7.8 5.5
45.5   3.2 5.0   1.8 2.0

> DF3 <- data.frame(as.table(as.matrix(DF2)))
  Var1  Var2 Freq
1   46 110.5  6.1
2 45.5 110.5  3.2
3   46   111  4.5
4 45.5   111  5.0
5   46 111.5  7.8
6 45.5 111.5  1.8
7   46   112  5.5
8 45.5   112  2.0

But the latitude and longitude get converted to factors and we lose the column names:

> DF3 <- data.frame(as.table(as.matrix(DF2)))
> colnames(DF3) <- c("latitude", "longitude", "Precip")
> DF3$latitude <- as.numeric(as.character(DF3$latitude))
> DF3$longitude <- as.numeric(as.character(DF3$longitude))

----------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

From: lily li <[hidden email]>
Sent: Tuesday, November 13, 2018 10:50 PM
To: David L Carlson <[hidden email]>
Cc: Sarah Goslee <[hidden email]>; R mailing list <[hidden email]>
Subject: Re: [R] How to create gridded data

Thanks, Sarah's answer helps the question. Now how to change the gridded data back to DF1 format? I don't know how to name the format, thanks.

On Tue, Nov 13, 2018 at 10:56 PM David L Carlson <mailto:[hidden email]> wrote:
Sarah's answer is probably better depending on what you want to do with the resulting data, but here's a way to go from your original DF1 to DF2:

> DF1 <- structure(list(latitude = c(45.5, 45.5, 45.5, 45.5, 46, 46, 46,
+         46), longitude = c(110.5, 111, 111.5, 112, 110.5, 111, 111.5,
+         112), Precip = c(3.2, 5, 1.8, 2, 6.1, 4.5, 7.8, 5.5)),
+         class = "data.frame", row.names = c(NA, -8L))
>
# Convert to table with xtabs()
> DF2 <- xtabs(Precip~latitude+longitude, DF1)
>

# Reverse the order of the latitudes
> DF2 <- DF2[rev(rownames(DF2)), ]
> DF2
        longitude
latitude 110.5 111 111.5 112
    46     6.1 4.5   7.8 5.5
    45.5   3.2 5.0   1.8 2.0

# Convert to a data frame
> DF2 <- as.data.frame.matrix(DF2)
> DF2
     110.5 111 111.5 112
46     6.1 4.5   7.8 5.5
45.5   3.2 5.0   1.8 2.0

----------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352


-----Original Message-----
From: R-help <mailto:[hidden email]> On Behalf Of Sarah Goslee
Sent: Tuesday, November 13, 2018 8:16 AM
To: lily li <mailto:[hidden email]>
Cc: r-help <mailto:[hidden email]>
Subject: Re: [R] How to create gridded data

If you want an actual spatial dataset, the best place to ask is R-sig-geo

R has substantial capabilities for dealing with gridded spatial data,
including in the sp, raster, and sf packages.

Here's one approach, creating a SpatialGridDataFrame, which can be
exported in any standard raster format using the rgdal package.

DF2 <- DF1
coordinates(DF2) <- ~longitude + latitude
gridded(DF2) <- TRUE
fullgrid(DF2) <- TRUE

I recommend Roger Bivand's excellent book:
https://urldefense.proofpoint.com/v2/url?u=https-3A__www.springer.com_us_book_9781461476177&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=veMGHMCNZShld-KX-bIj4jRE_tP9ojUvB_Lqp0ieSdk&m=vZqNKoDe8N1TzBzeK12g2oa0cBS8VD6NDCs-hUhvt5o&s=B73PwZQrdKUmM1ML2Y5zjaEz7xqkHlzBDCrhluogK2U&e=

and there are abundant web tutorials.

Sarah
On Tue, Nov 13, 2018 at 2:22 AM lily li <mailto:[hidden email]> wrote:

>
> Hi R users,
>
> I have a question about manipulating data. For example, I have DF1 as the
> following, how to transform it to a gridded dataset DF2? In DF2, each value
> Precip is an attribute of the corresponding grid cell. So DF2 is like a
> spatial surface, and can be imported to ArcGIS. Thanks for your help.
>
> DF1
> latitude   longitude   Precip
> 45.5           110.5         3.2
> 45.5           111            5.0
> 45.5           111.5         1.8
> 45.5           112            2.0
> 46              110.5         6.1
> 46              111            4.5
> 46              111.5         7.8
> 46              112            5.5
> ...
>
>
> DF2
> 6.1   4.5   7.8   5.5
> 3.2   5.0   1.8   2.0
> ...
>


--
Sarah Goslee (she/her)
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.numberwright.com&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=veMGHMCNZShld-KX-bIj4jRE_tP9ojUvB_Lqp0ieSdk&m=vZqNKoDe8N1TzBzeK12g2oa0cBS8VD6NDCs-hUhvt5o&s=qSosThG59aeSFYzVFf1e-YQGbuBKVbvgVi1z9nFm884&e=

______________________________________________
mailto:[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=veMGHMCNZShld-KX-bIj4jRE_tP9ojUvB_Lqp0ieSdk&m=vZqNKoDe8N1TzBzeK12g2oa0cBS8VD6NDCs-hUhvt5o&s=2pS9yFu5bpcRyCi1vX_OEDD2Ie8ZihvOQrkDQSNu8RM&e=
PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=veMGHMCNZShld-KX-bIj4jRE_tP9ojUvB_Lqp0ieSdk&m=vZqNKoDe8N1TzBzeK12g2oa0cBS8VD6NDCs-hUhvt5o&s=1brzEOjZ4EUr_llqwyO274DfJfsOpRBI-pmd-hp0WAQ&e=
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.