Dear, I need help on which.min and which.max. functions. Is there a function to fetch me the point that in vector that gives median value such like the commands for minimum and maximum values. Thanks.
which function
3 messages · Gafar Matanmi Oyeyemi, Jeff Newmiller, Jim Lemon
The median is not always a member of the data set. What do you really want? I for one would want people to follow the guidance in the footer on every email on this mailing list.
Sent from my phone. Please excuse my brevity. On June 4, 2016 9:01:41 AM PDT, Gafar Matanmi Oyeyemi <gmoyeyemi at gmail.com> wrote: >Dear, >I need help on which.min and which.max. functions. Is there a function >to >fetch me the point that in vector that gives median value such like the >commands for minimum and maximum values. >Thanks. > > [[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 >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]
Hi Gafar,
As Jeff has pointed out, the median value may not exist within the
dataset. However, this function will give you either the position of
the value that is the median, or the position of the two closest
values if none equal the median. Be aware that this function may fall
victim to the "indistinguishable difference" problem (FAQ 7.31).
which.median<-function(x) {
xmed<-median(x)
if(any(xmed==x)) {
wmed<-which(xmed==x)
} else {
fw<-which.min(abs(xmed-x))
rw<-1+length(x)-which.min(abs(xmed-rev(x)))
if(fw==rw) {
wmed<-fw
} else {
wmed<-c(fw,rw)
}
}
return(wmed)
}
Jim
On Sun, Jun 5, 2016 at 2:01 AM, Gafar Matanmi Oyeyemi
<gmoyeyemi at gmail.com> wrote:
Dear,
I need help on which.min and which.max. functions. Is there a function to
fetch me the point that in vector that gives median value such like the
commands for minimum and maximum values.
Thanks.
[[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 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.