Displaying 1 result from an estimated 1 matches for "myecdf".
Did you mean:
mecdf
2011 Mar 10
1
getting percentiles by factor
...llowing data.frame:
myExample <- data.frame(Ret=seq(-2, 2.5,
by=0.5),PE=seq(10,19),Sectors=rep(c("Financial","Industrial"),5))
myExample <- na.omit(myExample)
Thanks to Patrick I I managed to put together the following lines which does
it for the "Ret" column:
myecdf <- function(x, sortAsc) {
w1 <- ecdf(x$Ret)
w2 <- if (sortAsc) w1(x$Ret) * 100 else abs(w1(x$Ret) * 100 - 100)
w3 <- transform(x, myPerc=w2)
return(w3)
}
myExampleEnd <- lapply(split(myExample, myExample$Sectors), myecdf,
sortAsc="True")
myExampleEnd <- unsplit(myExample...