subset - Extracting summary statistics from subdatasets in R -


i subset dataset based on 2 variables.

my data this.

test.data <- data.frame(id=c(1,2,3,4,5,6,7,8,9,10), a=c("p1","p2","p3","p2","p3","p1","p3","p1","p3","p2"), b=c("l1","l3","l1","l3","l1","l1","l1","l1","l1","l2"),   d=c(3,5,6,7,8,3,4,5,5,2))   > test.data    id   b d 1   1 p1 l1 3 2   2 p2 l3 5 3   3 p3 l1 6 4   4 p2 l3 7 5   5 p3 l1 8 6   6 p1 l1 3 7   7 p3 l1 4 8   8 p1 l1 5 9   9 p3 l1 5 10 10 p2 l2 2                       split.datasets<-split(test.data, with(test.data, interaction(a,b)), drop = true)  > split.datasets $p1.l1    id   b d 1  1 p1 l1 3 6  6 p1 l1 3 8  8 p1 l1 5  $p3.l1    id   b d 3  3 p3 l1 6 5  5 p3 l1 8 7  7 p3 l1 4 9  9 p3 l1 5  $p2.l2    id   b d 10 10 p2 l2 2  $p2.l3    id   b d 2  2 p2 l3 5 4  4 p2 l3 7 

i need calculate summary statistics of mean , standard deviation 4th column ("d") every sub dataset.

could please me on this? many thanks!


Comments