# help with grouping data and calculating the means

5 messages
Open this post in threaded view
|

## help with grouping data and calculating the means

 Dear All, I would very much appreciate the help with following: I need to calculate the mean of  different lat/long points that should be grouped. However I would like that r excludes taking  values that are different in only last decimal. So instead 4 values in the group it would calculate the mean for only 3( excluding the ones that differs in only one decimal). # construct the dataframe `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) I would like to group the data and calculate means by group but in a way to exclude every number that differs in only last decimal. Also please see pdf. example-attached . Many thanks! Best wishes, Sasha -- Dr Sasha Kosanic Ecology Lab (Biology Department) Room M644 University of Konstanz Universitätsstraße 10 D-78464 Konstanz Phone: +49 7531 883321 & +49 (0)175 9172503 http://cms.uni-konstanz.de/vkleunen/https://tinyurl.com/y8u5wyojhttps://tinyurl.com/cgec6tu______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. dataset example.pdf (315K) Download Attachment
Open this post in threaded view
|

## Re: help with grouping data and calculating the means

 Use round() with the appropriate  "digits" argument. Then use unique() to define your groups. HTH, B. > On 2018-11-15, at 11:48, sasa kosanic <[hidden email]> wrote: > > Dear All, > > I would very much appreciate the help with following: > I need to calculate the mean of  different lat/long points that should be > grouped. > However I would like that r excludes taking  values that are different in > only last decimal. > So instead 4 values in the group it would calculate the mean for only 3( > excluding the ones that differs in only one decimal). > # construct the dataframe > `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) > > > I would like to group the data and calculate means by group but in a way to > exclude every number that differs in only last decimal. > > > Also please see pdf. example-attached . > > Many thanks! > Best wishes, > Sasha > > -- > > Dr Sasha Kosanic > Ecology Lab (Biology Department) > Room M644 > University of Konstanz > Universitätsstraße 10 > D-78464 Konstanz > Phone: +49 7531 883321 & +49 (0)175 9172503 > > http://cms.uni-konstanz.de/vkleunen/> https://tinyurl.com/y8u5wyoj> https://tinyurl.com/cgec6tu> ______________________________________________ > [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-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|