[R] quntile(table)?

2007-08-28 Thread Seung Jun
Hi,

I have data in the following form:

  index  count
-7  32
 19382
 22192
 7 190
11 201

I'd like to get quantiles from the data.  I thought about something like this:

  index - c(-7, 1, 2, 7, 11)
  count - c(32,  9382, 2192, 190, 201)
  quantile(rep(index, count))

It answers correctly, but I feel it's wasteful especially when count
is generally large.  So, my question is, is there a way to get
quantiles directly from this table (without coding at a low level)?

Thanks,
Seung

__
R-help@stat.math.ethz.ch mailing list
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.


[R] Fold in R?

2005-03-27 Thread Seung Jun
Fold in Mathematica (or reduce in Python) works as follows:
Fold[f, x, {a, b, c}] := f[f[f[x,a],b],c]
That is, f is a binary operator, x is the initial value, and the results 
are cascaded along the list.  I've found it useful for reducing lists 
when I only have a function that accepts two arguments (e.g., merge in R).

Is there any R equivalent?  I'm a newbie in R and having a hard time 
finding such one.  Thank you.

Seung
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] which.pmin?

2005-01-21 Thread Seung Jun
I have two vectors (k.floor and k.ceiling) of integers of the same
length, and a function (fpr).
   b - 10:40
   k.floor - floor(log(2) * b)
   k.ceiling - ceiling(log(2) * b)
   fpr.floor - fpr(b, k.floor)
   fpr.ceiling - fpr(b, k.ceiling)
If R had a element-wise ternary function, I'd like to do something like 
this:

   (fpr.floor  fpr.ceiling) ? k.floor : k.ceiling
That is, I'd like to go through the two vectors in parallel, picking
the one that returns the lower value of fpr. Failing to find such a
function, I wrote the following two lines:
   ind - sapply(data.frame(rbind(fpr.floor,fpr.ceiling)), which.min)
   opt.k - cbind(k.floor,k.ceiling)[1:length(ind)+length(ind)*(ind-1)]
opt.k is the vector I want, but I guess I abuse some functions here.
I'd like to ask the experts, What is the proper R-way to do this?
The API should be like which.pmin(FUN, X, Y, ...) that returns a
vector of the same length as X (and Y), provided that X, Y, ... have
the same length. Please fill the function body.
Seung
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html