Q:

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.

A:

You can try
 apply(obs, 1, function(x) quantile(x[x>=1], probs=.95))

