[R] Coding help
Petr Savicky
savicky at cs.cas.cz
Wed Feb 29 19:23:49 CET 2012
On Wed, Feb 29, 2012 at 11:58:04AM -0500, Ayyappa Chaturvedula wrote:
> Dear Group,
>
> I have the following dataset:
> ID REPI DV CONC SS
> 1 1 156.84 116 0
> 1 2 146.56 116 0
> 1 3 115.13 116 0
> 1 4 207.81 116 0
> 1 5 129.53 116 0
> 1 6 151.48 116 0
> 1 7 158.95 116 0
> 1 8 192.37 116 0
> 1 9 32.97 116 0
> 1 10 151.66 116 0
>
> I want to calculate the percentile of each CONC within ID=i and add as a
> column "Percentile". I got some help from R-tutorial on percentile but I
> am not able loop the function to calculate percentile/individual. So, I
> want the calculation to include only the ID=1 DVs to calculate the
> pecentile of conc=116.
Hi.
Can you provide a numerical example? This may require some
more data, where the column CONC has more than one value.
Another question is, what do you mean by computing percentile
for data. I would expect that you specify a number P, such
that 0 \le P < 100 and compute P-th percentile in some data.
Do you want to compute the inverse operation? This would
mean to compute P for each value in the data. For your
column DV, this would be
DV <- c(156.84,146.56,115.13,207.81,129.53,151.48,158.95,192.37,32.97,151.66)
p <- 100*(rank(DV)-1)/length(DV)
cbind(DV, p)
DV p
[1,] 156.84 60
[2,] 146.56 30
[3,] 115.13 10
[4,] 207.81 90
[5,] 129.53 20
[6,] 151.48 40
[7,] 158.95 70
[8,] 192.37 80
[9,] 32.97 0
[10,] 151.66 50
This need not be, what you want. In this case, provide a numerical
example.
Petr Savicky.
More information about the R-help
mailing list