[R] Simple Binning of Values
Martin Striz
mstriz at gmail.com
Tue Jun 12 07:51:21 CEST 2012
Hi, I just joined the list, but here's a suggestion.
x <- c(123, 48, 342, 442, 43, 232, 32, 129, 191, 147)
bins <- as.data.frame(table(cut(x, breaks=c(0, 100, 200, 300, 400, 500),
labels=c("0-100", "100-200", "200-300", "300-400", "400-500"))))
colnames(bins) <- c("bins", "count")
> bins
bins count
1 0-100 3
2 100-200 4
3 200-300 1
4 300-400 1
5 400-500 1
--Martin
-
----- Original Message -----
From: Kathryn B Walters-Conte <kbw1123 at yahoo.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Monday, June 11, 2012 5:22 PM
Subject: [R] Simple Binning of Values
Hello
I am very new to R. I have an R task to complete that I have not been
able to find a straightforward answer to as of yet. I have a list of
values. I would like to count the number of values that are in one
bin, the number that fall in the next bin, etc.
For example
My input file is: 123 48 342 442 43 232 32 129 191 147
I would like the output to be similar to:
0-100 3
100-200 4
200-3001
300-400 1
400-5001
Thus far I have tried working with hist, cut and split, but have not
gotten very far.
Thanks
Kat
More information about the R-help
mailing list