How can I get a percentile value for each dataframe row considering a subset of the data?
Asked Answered
I

1

6

I have a dataframe obs with 145 rowns and more than 1000 columns.

For each row I would like to extract the value of the 95th percentile but calculated only on the data greater or equal to 1.

I managed calculating a value for each row, considering all data, as follows:

p95.obs <- apply(obs,1,quantile,probs=c(.95))

To include the greater than option I tried

p95.obs <- apply(obs>=1,1,quantile,probs=c(.95))

but in this way I obtained only 1 for each row.

Inverson answered 6/5, 2015 at 13:2 Comment(0)
P
6

You can try

 apply(obs, 1, function(x) quantile(x[x>=1], probs=.95))
Pocahontas answered 6/5, 2015 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.