Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible Url : https://stat.ethz.ch/pipermail/r-help/attachments/20080302/86a07850/attachment.pl
See> length(unique(x))[1] 6> table(x)On 02/03/2008, Pete Dorothy <croero at gmail.com> wrote:> Hello, > > I am sorry for asking such a basic question. I could not find an answer to > it using google. > > I have a discrete variable (a vector x) taking for example the following > values : 0, 3, 4, 3, 15, 5, 6, 5 > > Is it possible to know how many different values (modalities) it takes ? > Here it takes 6 different values but the length of the vector is 8. > > I would like to know if there is a way to get the set of the > modalities {0,3,4,15,5,6} with the number of times each one is taken > {1,2,1,1,2,1} > > Thank you very much > > P.S. : is there some useful functions for discrete variables ? > > [[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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Try table(), with the name of your vector inside the parentheses. Ben -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Pete Dorothy Sent: Sunday, March 02, 2008 2:27 PM To: r-help at r-project.org Subject: [PS] [R] discrete variable Hello, I am sorry for asking such a basic question. I could not find an answer to it using google. I have a discrete variable (a vector x) taking for example the following values : 0, 3, 4, 3, 15, 5, 6, 5 Is it possible to know how many different values (modalities) it takes ? Here it takes 6 different values but the length of the vector is 8. I would like to know if there is a way to get the set of the modalities {0,3,4,15,5,6} with the number of times each one is taken {1,2,1,1,2,1} Thank you very much P.S. : is there some useful functions for discrete variables ? [[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.
Pete, try x <- c(0, 3, 4, 3, 15, 5, 6, 5) table(x) or length(table(x)) Cheers Andrew On Sun, Mar 02, 2008 at 09:27:20PM +0100, Pete Dorothy wrote:> Hello, > > I am sorry for asking such a basic question. I could not find an answer to > it using google. > > I have a discrete variable (a vector x) taking for example the following > values : 0, 3, 4, 3, 15, 5, 6, 5 > > Is it possible to know how many different values (modalities) it takes ? > Here it takes 6 different values but the length of the vector is 8. > > I would like to know if there is a way to get the set of the > modalities {0,3,4,15,5,6} with the number of times each one is taken > {1,2,1,1,2,1} > > Thank you very much > > P.S. : is there some useful functions for discrete variables ? > > [[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.-- Andrew Robinson Department of Mathematics and Statistics Tel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/
On 02-Mar-08 20:27:20, Pete Dorothy wrote:> Hello, > > I am sorry for asking such a basic question. I could not find > an answer to it using google. > > I have a discrete variable (a vector x) taking for example the > following values : 0, 3, 4, 3, 15, 5, 6, 5 > > Is it possible to know how many different values (modalities) > it takes? > Here it takes 6 different values but the length of the vector is 8. > > I would like to know if there is a way to get the set of the > modalities {0,3,4,15,5,6} with the number of times each one is > taken {1,2,1,1,2,1}This particulat kind of question is very simple: table(c(0, 3, 4, 3, 15, 5, 6, 5)) # 0 3 4 5 6 15 # 1 2 1 2 1 1 Note that the first row of the output is simply the column names, and is not part of the value returned by table() in this case, which is the vector c(1,2,1,2,1,1) printed in the second row. table(c(0, 3, 4, 3, 15, 5, 6, 5))[4] # 5 # 2 table(c(0, 3, 4, 3, 15, 5, 6, 5))[4] + 1.1 # 5 # 3.1 sum(table(c(0, 3, 4, 3, 15, 5, 6, 5))) # [1] 8 Hoping this helps.> Thank you very much > > P.S. : is there some useful functions for discrete variables ?Many! Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 02-Mar-08 Time: 20:52:40 ------------------------------ XFMail ------------------------------
"Pete Dorothy" <croero at gmail.com> wrote in news:fd75eef30803021227n2030d989iaeff1f3502327aba at mail.gmail.com:> Hello, > > I am sorry for asking such a basic question. I could not find an > answer to it using google. > > I have a discrete variable (a vector x) taking for example the > following values : 0, 3, 4, 3, 15, 5, 6, 5> > Is it possible to know how many different values (modalities) it > takes ? Here it takes 6 different values but the length of the > vector is 8.Try: test <- c(0, 3, 4, 3, 15, 5, 6, 5) length(table(test)) #[1] 6> I would like to know if there is a way to get the set of the > modalities {0,3,4,15,5,6} with the number of times each one is taken > {1,2,1,1,2,1}table(test) #test # 0 3 4 5 6 15 # 1 2 1 2 1 1> > Thank you very much > > P.S. : is there some useful functions for discrete variables ?Yes... <https://home.comcast.net/~lthompson221/Splusdiscrete2.pdf> -- David Winsemius