[R] discrete variable
David Winsemius
dwinsemius at comcast.net
Sun Mar 2 23:17:02 CET 2008
"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
More information about the R-help
mailing list