[R] Bucketting data
Marc Schwartz
MSchwartz at mn.rr.com
Mon Jun 20 15:02:25 CEST 2005
On Mon, 2005-06-20 at 13:50 +0100, Uzuner, Tolga wrote:
> Hi,
>
> Am sure this is a trivial question but for some reason, haven't been
> able to figure it out.
>
> I want to bucket data in a vector, and then iterate over the buckets.
>
> Say the data set is:
>
> > cleandata[,4]
> [1] 26 26 26 26 26 26 26 26 26 26 26 26 61 61 61 61
> 61 61 61 61 61 61 61 89 89 89 89 89 89 89 180 180 180 180
> 362 544 544 544
> [39] 544 544 544 544 544 544 544
>
> This has the buckets:
>
> 26 61 89 180 362 544
>
> I'd like something which gives me a vector of these buckets, i.e.
> bucket(cleandata[,4])=vector of 26 61 89 180 362 544
>
> and length(bucket(cleandata[,4]))=6
>
> Thanks,
> Tolga
> MyData
[1] 26 26 26 26 26 26 26 26 26 26 26 26 61 61 61 61 61
[18] 61 61 61 61 61 61 89 89 89 89 89 89 89 180 180 180 180
[35] 362 544 544 544 544 544 544 544 544 544 544
> bucket <- unique(MyData)
> bucket
[1] 26 61 89 180 362 544
> length(bucket)
[1] 6
# If you want a count of each unique value:
> table(MyData)
MyData
26 61 89 180 362 544
12 11 7 4 1 10
HTH,
Marc Schwartz
More information about the R-help
mailing list