Message-ID: <6D781055-3752-40C6-92FC-A8A3CBCC5B95@kit.edu>
Date: 2018-11-16T06:39:22Z
From: Anthoni, Peter (IMK)
Subject: help with grouping data and calculating the means
In-Reply-To: <CAJanvzGg1cf_1sjoQxKZ1U++8iA0Nh2LVdkuMUaUoDUfuhx-HQ@mail.gmail.com>
Hi Sasa,
Those latitude look equidistant with a separation of 0.05.
I guess you want to calculate the zonal mean along the latitude, right?
#estimate the lower and upper latitude for the cut
lat.dist=0.05 #equidistant spacing along latitude
lat.min=min(df$LAT,na.rm=T)-lat.dist/2
lat.max=max(df$LAT,na.rm=T)+lat.dist/2
cat.lat=cut(df$LAT,breaks=seq(lat.min,lat.max,by=lat.dist));cat.lat
#just show which indices are grouped
tapply(df$TK.QUADRANT,cat.lat, paste,collapse=",")
#calculate the mean of whatever column. The lat.mean will have NA for any latitude cell where the df column has no data
lat.mean=tapply(df$TK.QUADRANT,cat.lat, mean)
#if you need to remove any potential NAs
lat.mean[!is.na(lat.mean)]
cheers/beste Gr??e
Peter
On 15. Nov 2018, at 17:48, sasa kosanic <sasa.kosanic at gmail.com<mailto:sasa.kosanic at gmail.com>> wrote:
`TK-QUADRANT` <- c(9161,9162,9163,9164,10152,10154,10161,10163)
LAT <- c(55.07496,55.07496,55.02495,55.02496
,54.97496,54.92495,54.97496,54.92496)
LON <-
c(8.37477,8.458109,8.37477,8.45811,8.291435,8.291437,8.374774,8.374774)
df <- data.frame(`TK-QUADRANT`=`TK-QUADRANT`,LAT=LAT,LON=LON)
[[alternative HTML version deleted]]