Hello, I have simulated 30 observations from a binomial(5,0.1) distribution. Now I need to make frequency table( that means I need to tally how many 0's , 1's 2's....... 5's) I know that the simple R function table() will do this, but I am afraid that some times I may get zero frequency for some particular values (for example in the above there are 5-0's 10-1's , 14-2's, 10-3's , 11-4's but no any 5's ) So I want to make by frequecy table ( as a date frame) as value freq 0 5 1 10 2 14 3 10 4 11 5 0 How can I create such a table? Forgive me if this is a very basic question. I am new to R. Thank you very much. -- View this message in context: http://r.789695.n4.nabble.com/Creating-a-frequency-table-for-binomial-varaible-tp4650286.html Sent from the R help mailing list archive at Nabble.com.
As I have to to this in a simulation study for 1000 such binomial variables, I have created a R function as below.. Am I doing in the correct way? or is there any other simplest ways? #using a user defined function to create a frequency distribution create.freq.table<- function(x){ values<-seq(0,5,by=1) level<-seq(0,6,by=1) freq.cut<-cut(x,breaks=level,right=FALSE) int.freq.table<-table(freq.cut) int.dataframe<-data.frame(int.freq.table) final.freq.table<-data.frame(cbind(values, Freq=int.dataframe[,2])) return(final.freq.table) } -- View this message in context: http://r.789695.n4.nabble.com/Creating-a-frequency-table-for-binomial-varaible-tp4650286p4650295.html Sent from the R help mailing list archive at Nabble.com.
Hello, Try table(x) # or table(dat$value) Hope this helps, Rui Barradas Em 21-11-2012 13:19, arun4 escreveu:> Hello, > I have simulated 30 observations from a binomial(5,0.1) distribution. > Now I need to make frequency table( that means I need to tally how many 0's > , 1's 2's....... 5's) > I know that the simple R function table() will do this, but I am afraid > that some times I may get zero frequency for some particular values (for > example in the above there are 5-0's 10-1's , 14-2's, 10-3's , 11-4's but no > any 5's ) > > So I want to make by frequecy table ( as a date frame) as > value freq > 0 5 > 1 10 > 2 14 > 3 10 > 4 11 > 5 0 > > > How can I create such a table? > Forgive me if this is a very basic question. I am new to R. > > Thank you very much. > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Creating-a-frequency-table-for-binomial-varaible-tp4650286.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.
Thank you A.K Btw in which package count() is available? -- View this message in context: http://r.789695.n4.nabble.com/Creating-a-frequency-table-for-binomial-varaible-tp4650286p4650305.html Sent from the R help mailing list archive at Nabble.com.
> I know that the simple R function table() will do this, but I am afraid > that some times I may get zero frequency for some particular valuesMake a factor out of your data, specifying all the levels you want counts for, and pass that factor to table(). E.g., > x <- rep(0:6, c(5,2,0,3,0,4,0)) > table(x) x 0 1 3 5 5 2 3 4 > table(factor(x, levels=0:10)) 0 1 2 3 4 5 6 7 8 9 10 5 2 0 3 0 4 0 0 0 0 0 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf > Of arun4 > Sent: Wednesday, November 21, 2012 5:20 AM > To: r-help at r-project.org > Subject: [R] Creating a frequency table for binomial varaible > > Hello, > I have simulated 30 observations from a binomial(5,0.1) distribution. > Now I need to make frequency table( that means I need to tally how many 0's > , 1's 2's....... 5's) > I know that the simple R function table() will do this, but I am afraid > that some times I may get zero frequency for some particular values (for > example in the above there are 5-0's 10-1's , 14-2's, 10-3's , 11-4's but no > any 5's ) > > So I want to make by frequecy table ( as a date frame) as > value freq > 0 5 > 1 10 > 2 14 > 3 10 > 4 11 > 5 0 > > > How can I create such a table? > Forgive me if this is a very basic question. I am new to R. > > Thank you very much. > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Creating-a-frequency- > table-for-binomial-varaible-tp4650286.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.
Thank you Bill Dunlap . This seems very simple. -- View this message in context: http://r.789695.n4.nabble.com/Creating-a-frequency-table-for-binomial-varaible-tp4650286p4650312.html Sent from the R help mailing list archive at Nabble.com.