Hello. I have a vector of length 2771 but it has only 87 different values. How can I obtain them? Thanks, Arnau.
On Tue, 2006-03-14 at 18:45 +0100, Arnau Mir wrote:> Hello. > > I have a vector of length 2771 but it has only 87 different values. > How can I obtain them? > > Thanks, > > Arnau.If you just want the unique values themselves, you can use: unique(vector) For example:> v[1] "b" "b" "c" "a" "a" "a" "c" "c" "c" "c"> unique(v)[1] "b" "c" "a" If you wanted counts of each unique value, you can use table():> table(v)v a b c 3 2 5 HTH, Marc Schwartz
> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Arnau Mir > Sent: Tuesday, March 14, 2006 12:45 PM > To: r-help at stat.math.ethz.ch > Subject: [R] different values of a vector > > > Hello. > > I have a vector of length 2771 but it has only 87 different values. > How can I obtain them?It depends on what obtain means. This should get you started. foo <- sample(1:87,2771,T) table(foo) #or... levels(as.factor(foo))> > Thanks, > > Arnau. > > ______________________________________________ > 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 >
?unique Arnau Mir wrote:> Hello. > > I have a vector of length 2771 but it has only 87 different values. > How can I obtain them? > > Thanks, > > Arnau. > > ______________________________________________ > 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