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 =============================================================================Please access the attached hyperlink for an important electronic communications disclaimer: http://www.csfb.com/legal_terms/disclaimer_external_email.shtml
I'm not certain what "buckets" are, but based on your example try ?unique On 6/20/05, Uzuner, Tolga <tolga.uzuner at csfb.com> 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 > > > >-- Sarah Goslee http://www.stringpage.com
?unique On Mon, 20 Jun 2005 13:50:22 +0100 "Uzuner, Tolga" <tolga.uzuner at csfb.com> 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 > > > > > > > > > > =============================================================================> Please access the attached hyperlink for an important electronic communications disclaimer: > > http://www.csfb.com/legal_terms/disclaimer_external_email.shtml > > ______________________________________________ > 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-- Department of Sociology Fudan University,Shanghai Blog:http://sociology.yculblog.com
?table maybe is what you want -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Uzuner, Tolga Sent: June 20, 2005 8:50 AM To: 'r-help at stat.math.ethz.ch' Subject: [R] Bucketting data 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 ============================================================================Please access the attached hyperlink for an important electronic communications disclaimer: http://www.csfb.com/legal_terms/disclaimer_external_email.shtml ______________________________________________ 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
try this:
unique(cleandata[, 4])
length(unique(cleandata[, 4]))
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Uzuner, Tolga" <tolga.uzuner at csfb.com>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, June 20, 2005 2:50 PM
Subject: [R] Bucketting data
> 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
>
>
>
>
>
>
>
>
>
>
=============================================================================>
Please access the attached hyperlink for an important electronic
> communications disclaimer:
>
> http://www.csfb.com/legal_terms/disclaimer_external_email.shtml
>
> ______________________________________________
> 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
>
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
Many thanks all, that was it. Regards, Tolga -----Original Message----- From: Marc Schwartz [mailto:MSchwartz at mn.rr.com] Sent: 20 June 2005 14:02 To: Uzuner, Tolga Cc: 'r-help at stat.math.ethz.ch' Subject: Re: [R] Bucketting data 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 =============================================================================Please access the attached hyperlink for an important electronic communications disclaimer: http://www.csfb.com/legal_terms/disclaimer_external_email.shtml