Hi, Try this.> sd(unlist(sapply(1:dim(p)[1],function(i)rep(p[i,1],p[i,2]))))-- View this message in context: http://r.789695.n4.nabble.com/sd-mean-with-a-frequency-distribution-matrix-tp4703218p4703220.html Sent from the R help mailing list archive at Nabble.com.
Or if you want to perform the calculation without using sd: sqrt((sum(p[,1]^2*p[,2])-(sum(p[,1]*p[,2]))^2/sum(p[,2]))/(sum(p[,2])-1)) -- View this message in context: http://r.789695.n4.nabble.com/sd-mean-with-a-frequency-distribution-matrix-tp4703218p4703231.html Sent from the R help mailing list archive at Nabble.com.
Thank you, I'll try as soon as possible! Il 13/Feb/2015 22:28 "JS Huang [via R]" < ml-node+s789695n4703231h1 at n4.nabble.com> ha scritto:> Or if you want to perform the calculation without using sd: > > sqrt((sum(p[,1]^2*p[,2])-(sum(p[,1]*p[,2]))^2/sum(p[,2]))/(sum(p[,2])-1)) > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://r.789695.n4.nabble.com/sd-mean-with-a-frequency-distribution-matrix-tp4703218p4703231.html > To unsubscribe from sd, mean with a frequency distribution matrix, click > here > <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4703218&code=ZG9yaWFuLmdyZWxsaUBnbWFpbC5jb218NDcwMzIxOHwtOTUyODE5MTM5> > . > NAML > <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >-- View this message in context: http://r.789695.n4.nabble.com/sd-mean-with-a-frequency-distribution-matrix-tp4703218p4703232.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Hi, For the second one, sqrt((sum(p[,1]^2*p[,2])-(sum(p[,1]*p[,2]))^2/sum(p[,2]))/(sum(p[,2])-1)), please refer to the following link for an example to explain how it works. http://www.lboro.ac.uk/media/wwwlboroacuk/content/mlsc/downloads/var_stand_deviat_group.pdf For the first one: sd(unlist(sapply(1:dim(p)[1],function(i)rep(p[i,1],p[i,2])))).\: sapply(1:dim(p)[1],function(i)rep(p[i,1],p[i,2])) to get all in the first column of the matrix repeated the number of times in the second column. After that, make the resulting list to become a vector so that it can be executed with sd function. Here is some illustrative example.> p[,1] [,2] [1,] 10 3 [2,] 20 4 [3,] 30 5> sapply(1:dim(p)[1],function(i)rep(p[i,1],p[i,2]))[[1]] [1] 10 10 10 [[2]] [1] 20 20 20 20 [[3]] [1] 30 30 30 30 30> unlist(sapply(1:dim(p)[1],function(i)rep(p[i,1],p[i,2])))[1] 10 10 10 20 20 20 20 30 30 30 30 30> sd(unlist(sapply(1:dim(p)[1],function(i)rep(p[i,1],p[i,2]))))[1] 8.348471 -- View this message in context: http://r.789695.n4.nabble.com/sd-mean-with-a-frequency-distribution-matrix-tp4703218p4703338.html Sent from the R help mailing list archive at Nabble.com.
Hi, Just learned another way to calculate sd for a frequency distribution matrix:> p <- matrix(c(10,3,20,4,30,5),ncol=2,byrow=TRUE) > p[,1] [,2] [1,] 10 3 [2,] 20 4 [3,] 30 5> rep(p[,1],p[,2])[1] 10 10 10 20 20 20 20 30 30 30 30 30> sd(rep(p[,1],p[,2]))[1] 8.348471 -- View this message in context: http://r.789695.n4.nabble.com/sd-mean-with-a-frequency-distribution-matrix-tp4703218p4703441.html Sent from the R help mailing list archive at Nabble.com.