R 2.1.1 Win 2k Would someone suggest a method (or methods) that can be used to determine ntile cutpoints of a vector, i.e. to determine values that can be used to divide a vector into thirds such as 0-33 centile, 34-66 centile, 67-100 centile. If for example I had a vector: 1,2,3,4,5,6,7,8,9 and wanted to divide the vector into thirds I would have cut-points of 3, and 6. Thanks, John John Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics Baltimore VA Medical Center GRECC and University of Maryland School of Medicine Claude Pepper OAIC University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 410-605-7119 - NOTE NEW EMAIL ADDRESS: jsorkin@grecc.umaryland.edu [[alternative HTML version deleted]]
?quantile quantile(runif(1000), probs=seq(0,1,1/3)) John Sorkin wrote:> R 2.1.1 > Win 2k > > Would someone suggest a method (or methods) that can be used to > determine ntile cutpoints of a vector, i.e. to determine values that can > be used to divide a vector into thirds such as 0-33 centile, 34-66 > centile, 67-100 centile. If for example I had a vector: > 1,2,3,4,5,6,7,8,9 > and wanted to divide the vector into thirds > I would have cut-points of 3, and 6. > Thanks, > John > > John Sorkin M.D., Ph.D. > Chief, Biostatistics and Informatics > Baltimore VA Medical Center GRECC and > University of Maryland School of Medicine Claude Pepper OAIC > > University of Maryland School of Medicine > Division of Gerontology > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > > 410-605-7119 > -- NOTE NEW EMAIL ADDRESS: > jsorkin at grecc.umaryland.edu > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894
You could try using "cut":> cut(1:9, breaks = 3)[1] (0.992,3.66] (0.992,3.66] (0.992,3.66] (3.66,6.34] (3.66,6.34] [6] (3.66,6.34] (6.34,9.01] (6.34,9.01] (6.34,9.01] Levels: (0.992,3.66] (3.66,6.34] (6.34,9.01]>Quantile is another possible solution to get break points:> quantile(1:9, p = c(0, .33, .66, 1))0% 33% 66% 100% 1.00 3.64 6.28 9.00>You could use rounding if you want the integers, or use the given cutpoints. Hope this helps, Matt Wiener -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of John Sorkin Sent: Friday, July 15, 2005 8:48 AM To: r-help at stat.math.ethz.ch Subject: [R] Dividing a vector into ntiles R 2.1.1 Win 2k Would someone suggest a method (or methods) that can be used to determine ntile cutpoints of a vector, i.e. to determine values that can be used to divide a vector into thirds such as 0-33 centile, 34-66 centile, 67-100 centile. If for example I had a vector: 1,2,3,4,5,6,7,8,9 and wanted to divide the vector into thirds I would have cut-points of 3, and 6. Thanks, John John Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics Baltimore VA Medical Center GRECC and University of Maryland School of Medicine Claude Pepper OAIC University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 410-605-7119 -- NOTE NEW EMAIL ADDRESS: jsorkin at grecc.umaryland.edu [[alternative HTML version deleted]] ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Here is an example that shows how to divide a vector into "quartiles" and create a categorical (factor) variable with 4 levels ("A", "B", "C", "D") from it: x <- rnorm(100) xcat <- factor(cut(x, quantile(x), include.lowest = TRUE), labels = LETTERS[1:4]) table(xcat) Ravi.> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch [mailto:r-help- > bounces at stat.math.ethz.ch] On Behalf Of John Sorkin > Sent: Friday, July 15, 2005 8:48 AM > To: r-help at stat.math.ethz.ch > Subject: [R] Dividing a vector into ntiles > > R 2.1.1 > Win 2k > > Would someone suggest a method (or methods) that can be used to > determine ntile cutpoints of a vector, i.e. to determine values that can > be used to divide a vector into thirds such as 0-33 centile, 34-66 > centile, 67-100 centile. If for example I had a vector: > 1,2,3,4,5,6,7,8,9 > and wanted to divide the vector into thirds > I would have cut-points of 3, and 6. > Thanks, > John > > John Sorkin M.D., Ph.D. > Chief, Biostatistics and Informatics > Baltimore VA Medical Center GRECC and > University of Maryland School of Medicine Claude Pepper OAIC > > University of Maryland School of Medicine > Division of Gerontology > Baltimore VA Medical Center > 10 North Greene Street > GRECC (BT/18/GR) > Baltimore, MD 21201-1524 > > 410-605-7119 > -- NOTE NEW EMAIL ADDRESS: > jsorkin at grecc.umaryland.edu > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting- > guide.html