Is there simply a "Mode" function in R?
For 4d.
What is the range? Initially, I thought it would be 0 -> Inf
Since ln(0) = error and ln(Inf) = Inf.. this seems like an issue!
From: gov2001-l-bounces at
lists.fas.harvard.edu [mailto:gov2001-l-bounces at
lists.fas.harvard.edu] On Behalf Of Johnathan Boysielal
Sent: Monday, February 16, 2009 8:31 PM
To: gov2001-l at
lists.fas.harvard.edu
Subject: Re: [gov2001-l] R command for tabulating frequency
If you have a vector like n <- c(1, 2, 3, 4, 1, 2, 3, 2, 1, 2)
q <- table(n);q # will generate a frequency table
n
1 2 3 4
3 4 2 1
You can also apply operations like max() or mean() to q, and use it to subset the original
vector. E.g.:
unique(n[q>2]) #will list all the elements of n appearing more than 2 times
[1] 1 2
Hope that helps,
John
On Mon, Feb 16, 2009 at 6:39 PM, Rachel West <rwest817 at gmail.com<mailto:rwest817
at gmail.com>> wrote:
Very elementary question, I'm sure, but I'm new to R :
What is a command in R which would return the frequency elements in a vector, and could be
applied with "any" to recognize when a threshold frequency has been achieved?
For example, if I have a vector
n <- [1, 2, 3, 4, 1, 2, 3, 2, 1, 2],
is there a command that will output the number of instances of the most frequent element
(i.e, "2" is repeated 4 times), or something similarly useful?
Thanks,
Rachel
_______________________________________________
gov2001-l mailing list
gov2001-l at lists.fas.harvard.edu<mailto:gov2001-l at lists.fas.harvard.edu>
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l