0
$\begingroup$

Age 20 30 40 50 41 I would appreciate R code that would group my data into factors e.g 20-30 is 1 factor and so on.

$\endgroup$

closed as off-topic by kjetil b halvorsen, Michael Chernick, StatsStudent, Siong Thye Goh, whuber Jun 12 at 17:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – kjetil b halvorsen, Michael Chernick, StatsStudent, Siong Thye Goh, whuber
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ Hi! Welcome to Cross Validated! Please remember this is a Statistics-focus site and therefore code questions are not often welcome! This often comes as a surprise to many people in the software industry, but this world has much more stuff than code! stackoverflow.com is a great site to discuss those few things that are actually code $\endgroup$ – David Jun 12 at 16:05
  • 1
    $\begingroup$ See rdocumentation.org/packages/base/versions/3.6.0/topics/cut. $\endgroup$ – Ahmed Ali Jun 12 at 16:31
  • $\begingroup$ Answers depend on the purpose of sorting data into intervals and on the number of intervals you want. One simple strategy in R is to use the binning used in making a histogram. My data x are 50 rounded obs, from normal $\mu = 50, \sigma = 6.$ Min=45, Max=71. Code hist(x, plot=F)$breaks returns cut points 45, 50, 55, 60, 65, 70, 75. This method tends to give 'nice' endpoints (such as multiples of 5 and 10 here). You can suggest the approximate number of bins, if you don't like the default choice. $\endgroup$ – BruceET Jun 12 at 17:29

Browse other questions tagged or ask your own question.