Recoding of continuous variable into categories in R studio

Hello all R users
I wanted to know how to recode Continuous variable into categories.
I have a data in which birthweight are available in which I want to categorize the birthweight into 4 groups.

suggest what code I can use for grouping of the variable.

Hi @pratibha12,
The cut() function can do what you require. You can also set your own breakpoints, if preferred.

# make some dummy data
birthwt <- rnorm(20, 3.0, 0.5)
birthwt

cut(birthwt, breaks=4,
    labels=c("small","medium",
	      "large","very_large"))
help(cut)

thanks for your response.
here i am sharing my data
q = 2250
3400
3100
2250
2950
2500
2700
2900
2700
3250
3000
2800
2550
2600
3250
1518
3218
3250
3400
3100
2600
3000
2600
600
in this case I want 4 categories like this
<=500 = extremly low
501-1000 = low
1001- 1500= average

1500 = normal

please suggest what to do in this type of cases

Some ‘ifelse’ functions should do.