An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091102/1efe444c/attachment-0001.pl>
Frequency
7 messages · Val, Jorge Ivan Velez, Joe King +3 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091102/a6a60515/attachment-0001.pl>
sorry, I forgot to send my reply to the list, I got to remember to hit reply all: So I set up a dummy matrix, v1,v2,v3,v4, an datamatrix v1 = c(5,3,4) v2 = c(6,4,6) v3 = c(9,7,10) v4 = c(10,10,18) datamatrix=c(v1,v2,v3,v4) then do sort(table(datamatrix)) Joe King 206-913-2912 jp at joepking.com "Never throughout history has a man who lived a life of ease left a name worth remembering." --Theodore Roosevelt -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Val Sent: Monday, November 02, 2009 10:35 AM To: r-help at r-project.org Subject: [R] Frequency BAYESIAN INFERENCES FOR MILKING TEMPERAMENT IN CANADIAN HOLSTEINS Hi All, I have a data set "x" with several variables. Sample of the data is shown below V1 v2 v3 v4 5 6 9 10 3 4 7 10 4 6 10 18 I want the frequency of each data point sorted by their occurrence. Below is the output that I want 10 =3 6=2 4=2 9=1 5=1 7=1 3=1 How do I do it in R? Thanks in advance Val ______________________________________________ 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.
Thank you Jorge and
res <- table(unlist(x)) res[order(res, decreasing = TRUE)] # 10 4 6 3 5 7 9 18 # 3 2 2 1 1 1 1 1
This one works fine for me. Is it possible to transpose it? I tried t(res[order(res, decreasing = TRUE)]), but it did not work! I want the result like this 10 2 4 2 6 2 3 1 . . . . On Mon, Nov 2, 2009 at 1:45 PM, Jorge Ivan Velez
<jorgeivanvelez at gmail.com> wrote:
Hi Val, Here is a suggestion: res <- table(unlist(x)) res[order(res, decreasing = TRUE)] # 10 ?4 ?6 ?3 ?5 ?7 ?9 18 # ?3 ?2 ?2 ?1 ?1 ?1 ?1 ?1 HTH, Jorge On Mon, Nov 2, 2009 at 1:35 PM, Val <> wrote:
BAYESIAN INFERENCES FOR MILKING TEMPERAMENT IN CANADIAN HOLSTEINS Hi All, I have a data ?set "x" ?with several variables. Sample of the data is shown below ?V1 ?v2 ?v3 ? v4 ? 5 ? ?6 ? ?9 ? 10 ?3 ? ?4 ? ?7 ? 10 ?4 ? ?6 ? 10 ? 18 I want the frequency ?of each ?data point sorted by their occurrence. Below is the output that I want 10 ? ?=3 6=2 4=2 9=1 5=1 7=1 3=1 How do I do it in R? Thanks in advance Val ? ? ? ?[[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.
? ? ? ?[[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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091102/9715049c/attachment-0001.pl>
On Nov 2, 2009, at 2:49 PM, Jorge Ivan Velez wrote:
Hi Ashta,
Yes, it is possible. Here is a suggestion:
# Data set
x <- read.table(textConnection("v1 v2 v3 v4
5 6 9 10
3 4 7 10
4 6 10 18"), header = TRUE)
closeAllConnections()
# Table
res <- table(data.matrix(x))
f <- sort(res, decreasing = TRUE)
data.frame(value = names(f), counts = f)
# :-)
require(fortunes)
fortune('Only how')
HTH, Jorge On Mon, Nov 2, 2009 at 2:26 PM, Ashta <> wrote:
Thank you Jorge and
# 10 4 6 3 5 7 9 18 # 3 2 2 1 1 1 1 1
This one works fine for me. Is it possible to transpose it? I tried t(res[order(res, decreasing = TRUE)]), but it did not work!
And in the spirit of that fortune above, also look at: t(t(res[order(res, decreasing = TRUE)])) The extra t() coerces to a matrix and the outer t() does the transpose (I think).
David. >> >> I want the result like this >> 10 2 >> 4 2 >> 6 2 >> 3 1 >> . . >> . . >> >> >> >> >> On Mon, Nov 2, 2009 at 1:45 PM, Jorge Ivan Velez >> <> wrote: >>> Hi Val, >>> >>> Here is a suggestion: >>> >>> res <- table(unlist(x)) >>> res[order(res, decreasing = TRUE)] >>> # 10 4 6 3 5 7 9 18 >>> # 3 2 2 1 1 1 1 1 >>> >>> HTH, >>> Jorge >>> >>> >>> On Mon, Nov 2, 2009 at 1:35 PM, Val <> wrote: >>> >>>> BAYESIAN INFERENCES FOR MILKING TEMPERAMENT IN CANADIAN HOLSTEINS >>>> >>>> Hi All, >>>> >>>> I have a data set "x" with several variables. Sample of the >>>> data is >> shown >>>> below >>>> >>>> V1 v2 v3 v4 >>>> >>>> 5 6 9 10 >>>> >>>> 3 4 7 10 >>>> >>>> 4 6 10 18 >>>> >>>> >>>> >>>> I want the frequency of each data point sorted by their >>>> occurrence. >>>> >>>> >>>> >>>> Below is the output that I want >>>> >>>> 10 =3 >>>> >>>> 6=2 >>>> >>>> 4=2 >>>> >>>> 9=1 >>>> >>>> 5=1 >>>> >>>> 7=1 >>>> >>>> 3=1 >>>> >>>> How do I do it in R? >>>> >>>> >>>> >>>> Thanks in advance >>>> >>>> >>>> >>>> Val >>>> >>>> [[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. >>>> >>> >>> [[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. >>> >> > > [[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. David Winsemius, MD Heritage Laboratories West Hartford, CT
try sort (table(MAT), decreasing=T) if MAT is your matrix I think this is what you want. though if you want to sort by the first occurrence then it is a different story. Nikhil
On 2 Nov 2009, at 1:35PM, Val wrote:
V1 v2 v3 v4 5 6 9 10 3 4 7 10 4 6 10 18