Dear All If I have the following dataset V1 V2 x y y x z b a c b j d l c o How do I use R command to get the total number of different letter in column "V1" column "V1" has 7 different letters. Thank you -- View this message in context: http://r.789695.n4.nabble.com/Summing-up-Non-numeric-column-tp3077710p3077710.html Sent from the R help mailing list archive at Nabble.com.
Hi, One way would be> example <- read.table(textConnection("V1 V2+ x y + y x + z b + a c + b j + d l + c o"), header = TRUE)> closeAllConnections() > exampleV1 V2 1 x y 2 y x 3 z b 4 a c 5 b j 6 d l 7 c o> with(example, length(unique(V1)))[1] 7> with(example, length(unique(V2)))[1] 7 HTH, Jorge On Tue, Dec 7, 2010 at 11:56 PM, zhiji19 <> wrote:> > Dear All > > If I have the following dataset > > V1 V2 > x y > y x > z b > a c > b j > d l > c o > > How do I use R command to get the total number of different letter in > column > "V1" > column "V1" has 7 different letters. > > Thank you > -- > View this message in context: > http://r.789695.n4.nabble.com/Summing-up-Non-numeric-column-tp3077710p3077710.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
?unique -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of zhiji19 Sent: Wednesday, 8 December 2010 2:57 PM To: r-help at r-project.org Subject: [R] Summing up Non-numeric column Dear All If I have the following dataset V1 V2 x y y x z b a c b j d l c o How do I use R command to get the total number of different letter in column "V1" column "V1" has 7 different letters. Thank you -- View this message in context: http://r.789695.n4.nabble.com/Summing-up-Non-numeric-column-tp3077710p3077710.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Thanks a lot -- View this message in context: http://r.789695.n4.nabble.com/Summing-up-Non-numeric-column-tp3077710p3077733.html Sent from the R help mailing list archive at Nabble.com.
Hi, Still another way would be to count the levels of the factors (if it is indeed a factor): length(levels(example$V1)) Ivan Le 12/8/2010 06:08, Jorge Ivan Velez a ?crit :> Hi, > > One way would be > >> example<- read.table(textConnection("V1 V2 > + x y > + y x > + z b > + a c > + b j > + d l > + c o"), header = TRUE) >> closeAllConnections() >> example > V1 V2 > 1 x y > 2 y x > 3 z b > 4 a c > 5 b j > 6 d l > 7 c o >> with(example, length(unique(V1))) > [1] 7 >> with(example, length(unique(V2))) > [1] 7 > > HTH, > Jorge > > > On Tue, Dec 7, 2010 at 11:56 PM, zhiji19<> wrote: > >> Dear All >> >> If I have the following dataset >> >> V1 V2 >> x y >> y x >> z b >> a c >> b j >> d l >> c o >> >> How do I use R command to get the total number of different letter in >> column >> "V1" >> column "V1" has 7 different letters. >> >> Thank you >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/Summing-up-Non-numeric-column-tp3077710p3077710.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php
I think ?table is what you want. -- Bert On Wed, Dec 8, 2010 at 1:19 AM, Ivan Calandra <ivan.calandra at uni-hamburg.de> wrote:> Hi, > > Still another way would be to count the levels of the factors (if it is > indeed a factor): > length(levels(example$V1)) > > Ivan > > Le 12/8/2010 06:08, Jorge Ivan Velez a ?crit : >> >> Hi, >> >> One way would be >> >>> example<- read.table(textConnection("V1 V2 >> >> + x ? y >> + y ? x >> + z ? b >> + a ? c >> + b ? j >> + d ? l >> + c ? o"), header = TRUE) >>> >>> closeAllConnections() >>> example >> >> ? V1 V2 >> 1 ?x ?y >> 2 ?y ?x >> 3 ?z ?b >> 4 ?a ?c >> 5 ?b ?j >> 6 ?d ?l >> 7 ?c ?o >>> >>> with(example, length(unique(V1))) >> >> [1] 7 >>> >>> with(example, length(unique(V2))) >> >> [1] 7 >> >> HTH, >> Jorge >> >> >> On Tue, Dec 7, 2010 at 11:56 PM, zhiji19<> ?wrote: >> >>> Dear All >>> >>> If I have the following dataset >>> >>> V1 V2 >>> x ? y >>> y ? x >>> z ? b >>> a ? c >>> b ? j >>> d ? l >>> c ? o >>> >>> How do I use R command to get the total number of different letter in >>> column >>> "V1" >>> column "V1" has 7 different letters. >>> >>> Thank you >>> -- >>> View this message in context: >>> >>> http://r.789695.n4.nabble.com/Summing-up-Non-numeric-column-tp3077710p3077710.html >>> Sent from the R help mailing list archive at Nabble.com. >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> ? ? ? ?[[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > -- > Ivan CALANDRA > PhD Student > University of Hamburg > Biozentrum Grindel und Zoologisches Museum > Abt. S?ugetiere > Martin-Luther-King-Platz 3 > D-20146 Hamburg, GERMANY > +49(0)40 42838 6231 > ivan.calandra at uni-hamburg.de > > ********** > http://www.for771.uni-bonn.de > http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Bert Gunter Genentech Nonclinical Biostatistics