[R] Latitudinal mean of values in a data frame

arun smartpink111 at yahoo.com
Tue Dec 11 17:10:46 CET 2012


Hi,
In addition, you can also use:
?trunc(), ?substr() etc.

 aggregate(Value, by = list(floor(Lat)), FUN = function(x) signif(mean(x),2))
#  Group.1    x
#1      69 0.18
#2      70 0.16


  aggregate(Value, by = list(substr(Lat,1,2)), FUN = function(x) signif(mean(x),2))
#  Group.1    x
#1      69 0.18
#2      70 0.16

 aggregate(Value, by = list(trunc(Lat)), FUN = function(x) signif(mean(x),2)) 
 Group.1    x
#1      69 0.18
#2      70 0.16
A.K.


----- Original Message -----
From: Rui Barradas <ruipbarradas at sapo.pt>
To: Swagath Navin <s.n.manohar at rug.nl>
Cc: r-help at r-project.org
Sent: Tuesday, December 11, 2012 10:27 AM
Subject: Re: [R] Latitudinal mean of values in a data frame

Hello, again.

Another possibility is

aggregate(Value, by = list(floor(Lat)), FUN = mean)

Rui Barradas
Em 11-12-2012 11:17, Swagath Navin escreveu:
> Dear all,
> 
> I have a big file containing latitude points(-10 to 80) and corresponding values.
> Example data
> 
> Lat=c(69.48134, 69.49439, 69.50736, 69.52026, 69.52438, 69.53308, 69.53746, 69.54365, 69.54582, 69.6884, 69.69272, 69.998, 70.00055, 70.00106, 70.00295, 70.00308, 70.00363, 70.00427, 70.00665, 70.00906, 70.01049, 70.01053, 70.01075, 70.01208, 70.01236, 70.01418, 70.01452, 70.01646, 70.01983, 70.0209, 70.02298, 70.02386, 70.02533, 70.02534, 70.02856, 70.0291, 70.02983, 70.03091, 70.03267, 70.03423)
> 
> Value=c(0.18917075, 0.18856758, 0.1877328, 0.18664664, 0.18871901, 0.18528864, 0.18797649, 0.18999862, 0.1836383, 0.15414046, 0.18542965, 0.13914858, 0.1654665, 0.12885736, 0.18935319, 0.1912378, 0.14910094, 0.17590007, 0.18369354, 0.12546185, 0.16096813, 0.18851039, 0.14388486, 0.19098477, 0.17252013, 0.12965086, 0.12256515, 0.18159349, 0.15608113, 0.18742996, 0.13858418, 0.16865459, 0.19058037, 0.12531143, 0.19189732, 0.12019097, 0.1790819, 0.15086053, 0.18607724,  0.13330366)
> 
> dframe=data.frame(Lat, Value)
> 
> i would like to find latitudinal mean such that my output looks like the below:
> 
> Lat Value
> 69 0.18
> 70 0.16
> 
> I am thankful for any ideas how to perform this or which function i should look into.
> 
> Thanks a lot for your time,
> Cheers,
> Navin
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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.

______________________________________________
R-help at r-project.org mailing list
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.





More information about the R-help mailing list