unique breaks error in calculation of quantiles of a data frame in r

533 Views Asked by At

I have a dataframe as follows:

       AA        BB        CC       DD

a     name1    59.67      45.9     56.64 

b     name2      0          0       0.3

c     name3    7.14         0      0.55000000000000004

I am using dplyr package and I would like to rank each column based on its quartile. I am using the following command:

df_qnt <- df[2:4] %>% mutate_all(funs(quant = as.integer(cut(as.numeric(.), quantile(as.numeric(.)), include.lowest = TRUE ))))

But this error pops up:

 Error in mutate_impl(.data, dots) : 
 Evaluation error: 'breaks' are not unique.

I put quantile function inside unique function. Apparently there is no error but my output does not contain the ranking. Here is the command:

 df_qnt <- df[2:4] %>% mutate_all(funs(quant = as.integer(cut(as.numeric(.), unique(quantile(as.numeric(.))), include.lowest = TRUE ))))

Anybody can help me with this? Thanks

1

There are 1 best solutions below

0
On

Actually there was something wrong with Rstudio. My command works perfectly.

Sorry for inconvenience.