## How you might structure your workshops: ## Workshop 1 setwd('~/Desktop/workshops/01') ## Try out the command line ## 1. log(5) exp(3) ## 2. ## R code from after first class: ## saving objects from your workspace: m <- matrix(1:4, ncol=2) x <- 5 y <- 3 save(x, y, m, file='workshop1objects.RData') ## and then loading them later on load('workshop1objects.RData', verbose=TRUE) ## creating a vector a <- c(4,3,5) length(a) ## creating a function with just one argument my.mean <- function(x) { mu <- sum(x)^2 / length(x) return(mu) } ## applying that function: my.mean(a) my.mean(c(3,2,5,5,5,7)) a <- c(3,2,5,5,5,7) my.mean(a) b <- c(2,1,5,6,5,7) my.mean(b) c <- c(2,1,8,8,5,7) my.mean(c) ## creating a function with multiple arguments (and default values) my.fun.2 <- function(a=4, b=4, c=4) { d <- a^2+b^3 e <- d/c return(e^2) } my.fun.2(1,2,3) my.fun.2(2,1,3) my.fun.2(a=2,c=3,b=1) my.fun.2(a=2,c=3) my.fun.2() ## using a function to make a two panel plot make.panel <- function(dd, cc='black') { plot(dd, col=cc, pch=16, cex=1.2) } layout(matrix(1:2, ncol=2)) make.panel(dd=runif(10)) make.panel(dd=1:10, cc='blue')