Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 762
Corrado Avatar asked May 06 '15 13:05

Corrado


1 Answers

You can try

 apply(obs, 1, function(x) quantile(x[x>=1], probs=.95))
like image 193
akrun Avatar answered Oct 06 '22 19:10

akrun