[R] Replace array with percentile values

William Dunlap wdunlap at tibco.com
Mon Nov 5 04:34:44 CET 2012


rank() would do it:
   > x <- c(1,2,2,2,2,3,4,4,5,5)
   > rank(x, ties="max")/length(x)  * 100
    [1]  10  50  50  50  50  60  80  80 100 100
as would ecdf()
   > ecdf(x)(x)*100
    [1]  10  50  50  50  50  60  80  80 100 100

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of greggallen at gmail.com
> Sent: Sunday, November 04, 2012 7:22 PM
> To: r-help at r-project.org
> Subject: [R] Replace array with percentile values
> 
> Hi:
> 
> I have an array of measurements, that I've been doing linear
> regression model and AI models on.  Because there are many errors and
> the values are "ill-formed" I would like to copy the array, but
> replace each value with the PERCENTILE of that value, in the original
> array.
> 
> i.e.
> 
> mesments$V1:  9, 77, -1
> 
> would become: mesmentsCopy$V1: 50, 100, 0
> 
> The actual array has many more rows and columns, of course.
> 
> Cheers,
> 
> Greg Allen
> Freelance Techno-Slave
> SLC, Utah
> 
> ______________________________________________
> R-help at 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.




More information about the R-help mailing list