help with grouping data and calculating the means
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)