Note that, as requested in the comments, that this question has been revised.
Consider the following example:
df <- data.frame(FILTER = rep(1:10, each = 10), VALUE = 1:100)
I would like to, for each value of FILTER
, create a data frame which contains the 1st, 2nd, ..., 99th percentiles of VALUE
. The final product should be
PERCENTILE df_1 df_2 ... df_10
1 [first percentiles]
2 [second percentiles]
etc., where df_i
is based on FILTER == i
.
Note that FILTER
, although it contains numbers, is actually categorical.
The way I have been doing this is by using dplyr
:
nums <- 1:10
library(dplyr)
for (i in nums){
df_temp <- filter(df, FILTER == i)$VALUE
assign(paste0("df_", i), quantile(df_temp, probs = (1:99)/100))
}
and then I would have to cbind
these (with 1:99
in the first column), but I would rather not type in every single df
name. I have considered using a loop on the names of these data frames, but this would involve using eval(parse())
.