Gareth Campbell wrote:
Hello,
I have a matrix and I want to sample 20 rows that are the the percentiles of
0-100 in 0.05 increments.  I have a vector of my sequence

(0, 0.05, 0.10, 0.15,....1.0) and also

That's actually 21 entries, but that probabl doesn't matter...
a normalised vector of rownumbers.  That is, there are 234 rows (for
example) so I do

perc<-c(1:234/234)

which looks like a bunch of numbers from 0 - 1.

In Excel (which I try not to use at every possible occaison) you can use a
VLOOKUP function to say choose the rows from the perc vector that are the
closest match to the sequence vector - i.e. you can specify to choose the
"closest" match, it doesn't have to be an exact match.

In R, I'd normally use the grep command when I know it's an exact match.
 Does anyone know how to achieve this in R?

You could do it with approx.  That is:

rownum <- approxfun( (1:234 - 0.5)/234, 1:234, method="constant", rule=2)

Then rownum(0.05) will give 12, rownum(0.1) will give 23, etc.

Duncan Murdoch
Also, I've been getting heaps of help from everyone on this mailing list -
if I reply to the respondent and R Help again, will it show up in the
correct thread?  I haven't been able to say thankyou as I wasn't sure it
would show up in the thread.

Thanks




______________________________________________
R-help@r-project.org 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.

Reply via email to