Created
December 6, 2011 08:46
-
-
Save even4void/1437419 to your computer and use it in GitHub Desktop.
reproducible example in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # simulate some data | |
| set.seed(88) | |
| n <- 30 | |
| x <- runif(n) | |
| y <- 1.2 + 0.8*x + rnorm(n) | |
| g <- sample(letters[1:2], n, replace=TRUE) | |
| my.df <- data.frame(x=x, y=y, grp=factor(g)) | |
| # show data structure | |
| dput(my.df) | |
| # save results from a linear as plain text in home directory | |
| capture.output(summary(lm(y ~ x + grp, data=my.df)), file="~/my_df_lm.txt") | |
| # save a PNG graphic in home directory | |
| library(lattice) | |
| png("~/my_df_xyplot.png") | |
| xyplot(y ~ x | grp, data=my.df, type=c("p","smooth")) | |
| dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment