Ned
Ned

Reputation: 11

How to make a variable which assigns numbers based on a variable?

For example, I am trying to make a variable that will assign 1, 2, 3,4.

1 <25th percentile

2 >= 25th percentile upto 50th percentile

similarly, 3 and 4. and so on

Could anyone give me some clues in how I would complete this?

Upvotes: 1

Views: 27

Answers (1)

akrun
akrun

Reputation: 887173

We can specify the breaks as quantile in cut and then convert the factor output to integer with as.integer

as.integer(cut(v1, breaks = quantile(v1)))

Upvotes: 0

Related Questions