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
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, -1If 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
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.