Hi everyone,
I need your help on this dataset (sample):
region sector index
A health 0.94
B health 1.04
C health 1.12
D health 1.01
E health 1.01
F health 1.06
G health 1.00
H health 1.21
I health 1.08
J health 1.01
A edu 1.20
B edu 1.12
C edu 1.11
D edu 0.85
E edu 1.06
F edu 1.19
G edu 1.10
H edu 1.06
I edu 0.96
J edu 1.08
A trade 1.09
B trade 0.99
C trade 1.11
D trade 0.93
E trade 1.00
F trade 0.98
G trade 1.05
H trade 1.03
I trade 0.91
J trade 1.05
I would like to add new column (kuartile) in my dataset, the column values is the quartile of the other column (index) based on categories available in sector column using codes as follow:
x <- c(a = tes %>% filter(sector=="health"),
b = tes %>% filter(sector=="edu"),
c = tes %>% filter(sector=="trade"))
q = c(0.25, 0.5, 0.75)
tes2 <- for (i in seq_along(x))
{tes %>% mutate(kuartile=(case_when (indeks<=quantile(indeks, probs=q[1]) ~ "q1",
indeks > quantile(indeks, probs=q[1]) & indeks <= quantile(indeks, probs=q[2]) ~ "q2",
indeks > quantile(indeks, probs=q[2]) & indeks <= quantile(indeks, probs=q[3]) ~ "q3",
TRUE ~ "q4")
))}
tes2
However the result is NULL.