This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
r-tutorial [2011/10/12 23:57] liuyipei |
r-tutorial [2011/10/13 00:07] liuyipei |
||
---|---|---|---|
Line 12: | Line 12: | ||
# R as a graphics tool | # R as a graphics tool | ||
# Define a vector named cars with five values | # Define a vector named cars with five values | ||
- | cars <- c(1, | + | my.vector |
- | # Plot the values in cars with default options | + | # Some basic variables that come with R to play with |
- | plot(cars) | + | head(cars) |
+ | dim(cars) | ||
- | r <- rlnorm(1000) | + | plot(x=cars$speed, y=cars$dist |
- | h <- hist(r, | + | |
- | plot(h$counts, | + | |
- | log=" | + | |
- | | + | hist(cars$speed) |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
# Primitive data types | # Primitive data types | ||
Line 181: | Line 178: | ||
my.data <- as.matrix(read.table(" | my.data <- as.matrix(read.table(" | ||
- | |||
# The columns of a matrix can have symbolic names | # The columns of a matrix can have symbolic names | ||
Line 280: | Line 276: | ||
load(file=" | load(file=" | ||
ls() | ls() | ||
- | | ||
- | # source - read and execute from a text file containing an R script | + | </ |
- | # Debugging - Two main options | ||
- | # Sprinkle cat(...) liberally throughout your code to monitor what is going on. | ||
- | # debug(), undebug() - Turn on/off step through debugging for a function | ||
- | # SIMPLE STATISTICS | + | ====Basics==== |
- | # Some simple statistics - note that many functions that perform statistical tests | + | |
- | # etc, in R return list objects. | + | |
- | help(t.test) | + | |
- | ttest.result <- t.test(my.data[' | + | |
- | ttest.result | + | |
- | names(ttest.result) | + | |
- | ttest.result$statistic | + | |
- | ttest.result$p.value | + | |
- | + | ||
- | help(cor.test) | + | |
- | cor.results <- cor.test(my.data[' | + | |
- | + | ||
- | help(chisq.test) | + | |
- | chisq.results <- chisq.test(pheno.data$rides.bike, | + | |
- | chisq.results <- chisq.test(table(pheno.data$rides.bike, | + | |
- | + | ||
- | help(prcomp) | + | |
- | prcomp.results <- prcomp(my.data) | + | |
- | my.data[is.na(my.data)] <- 0 | + | |
- | prcomp.results <- prcomp(my.data) | + | |
- | + | ||
- | </ | + |