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.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to