Displaying 2 results from an estimated 2 matches for "psort".
Did you mean:
port
2006 Apr 10
2
Suggestions to speed up median() and has.na()
...return(NA)
half <- (n + 1)/2
if (n%%2 == 1) {
sort(x, partial = half)[half]
}
else {
sum(sort(x, partial = c(half, half + 1))[c(half, half +
1)])/2
}
}
<environment: namespace:stats>
Suggestion 1:
Replace the sort() calls with the .Internal(psort(x, partial)). This
will avoid unnecessary overhead, especially an expensive second check
for NAs using any(is.na(x)). Simple benchmarking with
x <- rnorm(10e6)
system.time(median(x))/system.time(median2(x))
where median2() is the function with the above replacements, gives
about 20-25% spee...
2004 Nov 03
2
Unexpected results from sort function when partial and index are used
Hi,
Consider the following example:
sort(10:1, partial=3)
## 1 2 3 7 6 5 4 8 9 10
sort(10:1, index=T)
## $x: 1 2 3 4 5 6 7 8 9 10
## $ix: 10 9 8 7 6 5 4 3 2 1
sort(10:1, partial=3, index=T)
## 1 2 3 7 6 5 4 8 9 10
The first 2 calls gave expected returns; however, the third one did not
returned an index as requested. I could not find anything about it in