[R] Replace array with percentile values

David Winsemius dwinsemius at comcast.net
Mon Nov 5 04:29:44 CET 2012


On Nov 4, 2012, at 7:22 PM, greggallen at gmail.com wrote:

> 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

If you are using the "$" function, you do not have an array but rather a dataframe. The distinction in R is not at all trivial. If this is a dataframe and you are only woring with one column then this might work (assuming that thememetsCopy alreadyexists) :

 mesmentsCopy$V1 <- 100*quantile(mesments$V1, (1:100)/100)

All untested. You were asked in the Posting Guide to present a means of creatine data that has the same structure. Using dput is a good way of presneting htat structure in ascii form.

> 
> 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.

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list