Calculating Quantiles in R

I have the following dataset:


var1 = rnorm(10000, 100,100)
var2 = rnorm(10000, 100,100)
var3 = rnorm(10000, 100,100)
var4 = rnorm(10000, 100,100)
var5 <- factor(sample(c("Yes", "No"), 1000, replace=TRUE, prob=c(0.4, 0.6)))
var6 <- factor(sample(c("Yes", "No"), 1000, replace=TRUE, prob=c(0.4, 0.6)))

my_data = data.frame( var1, var2, var3, var4, var5, var6)

I am trying to run the following code:

my_data %>%
    group_by(var5) %>%
    mutate(col1 = ntile(var1, 5))

This code works on this sample dataset, but on my real dataset - I always get the following error:

Error: Column 'col1' must be length xyz (the group size) or one, not abc

What kind of strategies can I use to avoid this error?


Strange error because you create a new column col1.

I am afraid the only thing you can do to get help is to show the actual code you used on the dataset and the first few lines of your dataset with:


This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.