# [R] Aggregate data to lower resolution

Thu Jan 19 23:58:44 CET 2017

```Milu,

To get the quickest help and keep everyone in the loop, you should cc the
help list.

I don't understand your question.  If you want the mean GDP use the mean
function, if you want the sum of the GDP use the sum function.

Jean

On Fri, Jan 13, 2017 at 5:33 PM, Miluji Sb <milujisb at gmail.com> wrote:

> Dear Jean,
>
> Greetings of the new year. Hope you are doing well.
>
> I apologise for writing to you off-list but this might be a really silly
> question and I wanted to clarify without bothering everyone. Would kindly
> help me out? Hope this is not too much of a bother.
>
> My original question was regarding aggregating data to 1 degree x 1
> degree. You had kindly provided the following solution:
>
> temp\$long1 <- floor(temp\$longitude)
> temp\$lat1 <- floor(temp\$latitude)
> temp1 <- aggregate(GDP ~ long1 + lat1, temp, mean)
>
> Everything works well, my only question (and confusion) is that for
> aggregating from 0.5 degree by 0.5 degree to 1 degree by 1 degree, should
> we use sum instead of mean?
>
> temp1 <- aggregate(GDP ~ long1 + lat1, temp, sum)
>
> I really hope I'm not bothering you too much. Thanks again.
>
> Sincerely,
>
> Milu
>
> On Fri, Jul 22, 2016 at 3:06 PM, Adams, Jean <jvadams at usgs.gov> wrote:
>
>> Milu,
>>
>> Perhaps an approach like this would work.  In the example below, I
>> calculate the mean GDP for each 1 degree by 1 degree.
>>
>> temp\$long1 <- floor(temp\$longitude)
>> temp\$lat1 <- floor(temp\$latitude)
>> temp1 <- aggregate(GDP ~ long1 + lat1, temp, mean)
>>
>>   long1 lat1        GDP
>> 1   -69  -55 0.90268640
>> 2   -68  -55 0.09831317
>> 3   -72  -54 0.22379000
>> 4   -71  -54 0.14067290
>> 5   -70  -54 0.00300380
>> 6   -69  -54 0.00574220
>>
>> Jean
>>
>> On Thu, Jul 21, 2016 at 3:57 PM, Miluji Sb <milujisb at gmail.com> wrote:
>>
>>> Dear all,
>>>
>>> I have the following GDP data by latitude and longitude at 0.5 degree by
>>> 0.5 degree.
>>>
>>> structure(list(longitude = c(-68.25, -67.75, -67.25, -68.25,
>>> -67.75, -67.25, -71.25, -70.75, -69.25, -68.75), latitude = c(-54.75,
>>> -54.75, -54.75, -54.25, -54.25, -54.25, -53.75, -53.75, -53.75,
>>> -53.75), GDP = c(1.683046, 0.3212307, 0.0486207, 0.1223268, 0.0171909,
>>> 0.0062104, 0.22379, 0.1406729, 0.0030038, 0.0057422)), .Names =
>>> c("longitude",
>>> "latitude", "GDP"), row.names = c(4L, 17L, 30L, 43L, 56L, 69L,
>>> 82L, 95L, 108L, 121L), class = "data.frame")
>>>
>>> I would like to aggregate the data 1 degree by 1 degree. I understand
>>> that
>>> the first step is to convert to raster. I have tried:
>>>
>>> rasterDF <- rasterFromXYZ(temp)
>>> r <- aggregate(rasterDF,fact=2, fun=sum)
>>>
>>> But this does not seem to work. Could anyone help me out please? Thank
>>> you
>>>
>>> Sincerely,
>>>
>>> Milu
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help