R version 2.11.1 (2010-05-31) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > .help.ESS <- help > options(STERM='iESS', editor='emacsclient') > mns09 <- replicate(10000, mean(rexp(9))) > library(ggplot2) Loading required package: reshape Loading required package: plyr Loading required package: grid Loading required package: proto > qplot(mns09, geom="density") > > > > > > > df <- do.call(data.frame(lapply(c(9,16,25,36), function(n)replicate(10000,mean(rexp(n)))))) Error in is.list(args) : 'args' is missing > str(lapply(c(9,16,25,36), function(n)replicate(10000,mean(rexp(n)))) + ) List of 4 $ : num [1:10000] 1.25 1.26 1.26 1.23 1.12 ... $ : num [1:10000] 1.065 1.375 1.241 0.933 1.272 ... $ : num [1:10000] 0.805 0.892 1.282 0.566 1.029 ... $ : num [1:10000] 1.14 1.004 0.92 1.132 0.674 ... > df <- do.call(data.frame,lapply(c(9,16,25,36), function(n)replicate(10000,mean(rexp(n))))) > > > > > > > > > > > fr <- melt(df, id=NULL, variable="sampleSize") > str(fr) 'data.frame': 40000 obs. of 2 variables: $ sampleSize: Factor w/ 4 levels "c.1.29655622722402..0.952362339617965..1.04390481342217..1.38089422931516..",..: 1 1 1 1 1 1 1 1 1 1 ... $ value : num 1.297 0.952 1.044 1.381 1.401 ... > names(fr$samplSize) <- c("09","16","25","36") Error in names(fr$samplSize) <- c("09", "16", "25", "36") : attempt to set an attribute on NULL > names(fr$sampleSize) <- c("09","16","25","36") > str(fr) 'data.frame': 40000 obs. of 2 variables: $ sampleSize: Factor w/ 4 levels "c.1.29655622722402..0.952362339617965..1.04390481342217..1.38089422931516..",..: 1 1 1 1 1 1 1 1 1 1 ... $ value : num 1.297 0.952 1.044 1.381 1.401 ... > > > > > > > str(fr) 'data.frame': 40000 obs. of 2 variables: $ sampleSize: Factor w/ 4 levels "c.1.29655622722402..0.952362339617965..1.04390481342217..1.38089422931516..",..: 1 1 1 1 1 1 1 1 1 1 ... $ value : num 1.297 0.952 1.044 1.381 1.401 ... > levels(fr$sampleSize) <- c("09","16","25","36") > str(fr) 'data.frame': 40000 obs. of 2 variables: $ sampleSize: Factor w/ 4 levels "09","16","25",..: 1 1 1 1 1 1 1 1 1 1 ... $ value : num 1.297 0.952 1.044 1.381 1.401 ... > > > > > > > qplot(value, data=fr, geom="density", color=sampleSize) > mns09 <- replicate(10000, mean(rexp(9))) > mns16 <- replicate(10000, mean(rexp(16))) > mns25 <- replicate(10000, mean(rexp(25))) > mns36 <- replicate(10000, mean(rexp(36))) > > > > > > > > > > > value <- c(mns09, mns16, mns25, mns36) > str(value) num [1:40000] 1.13 0.84 1.052 0.906 1.376 ... > > > > > > > > fr <- data.frame(value = value, sampleSize = rep(c("09","16","25","36"), each=10000)) > str(fr) 'data.frame': 40000 obs. of 2 variables: $ value : num 1.13 0.84 1.052 0.906 1.376 ... $ sampleSize: Factor w/ 4 levels "09","16","25",..: 1 1 1 1 1 1 1 1 1 1 ... > > \ Error: unexpected input in "\" > > > > > > > nmn09 <- replicate(10000, mean(rnorm(9))) > med09 <- replicate(10000, median(rnorm(9))) > > > > > > > > > > > > > > > > mean(nmn09); mean(med09) [1] 0.003062494 [1] 0.002347504 > > > > > sd(nmn09); sd(med09) [1] 0.3339833 [1] 0.4031011 > > > > > > > > qplot(c(nmn09, med09), geom="density", color = gl(2,10000,labels=c("mean","median"))) > stat <- gl(2,10000,labels=c("mean","median")) > str(stat) Factor w/ 2 levels "mean","median": 1 1 1 1 1 1 1 1 1 1 ... > qplot(c(nmn09, med09), geom="density", color=stat) > load("~/Downloads/long.rda") > str(long) 'data.frame': 80000 obs. of 4 variables: $ variable: Factor w/ 8 levels "Mean.n9","Mean.n16",..: 1 1 1 1 1 1 1 1 1 1 ... $ value : num -0.274 0.282 0.136 0.181 0.323 ... $ stat : Factor w/ 2 levels "mean","median": 1 1 1 1 1 1 1 1 1 1 ... $ size : Factor w/ 4 levels "9","16","25",..: 1 1 1 1 1 1 1 1 1 1 ... > > > > > > > > > > xtabs(~ stat + size, long) size stat 9 16 25 36 mean 10000 10000 10000 10000 median 10000 10000 10000 10000 > > > > > names(long) <- c("var", "value", "stat", "sz") > str(long) 'data.frame': 80000 obs. of 4 variables: $ var : Factor w/ 8 levels "Mean.n9","Mean.n16",..: 1 1 1 1 1 1 1 1 1 1 ... $ value: num -0.274 0.282 0.136 0.181 0.323 ... $ stat : Factor w/ 2 levels "mean","median": 1 1 1 1 1 1 1 1 1 1 ... $ sz : Factor w/ 4 levels "9","16","25",..: 1 1 1 1 1 1 1 1 1 1 ... > > > > > > > qplot(value, data=long, geom="density", color=stat, linetype=sz) > qplot(value, data=long, geom="density", color=stat, facets= ~sz) > Save workspace image? [y/n/c]: n Process R finished at Wed Sep 22 11:59:42 2010