################################################### ### chunk number 1: setopts ################################################### #line 31 "lab1.Rnw" options(continue=" ") ################################################### ### chunk number 2: arith1 ################################################### #line 222 "lab1.Rnw" 2+2 ################################################### ### chunk number 3: arith2 ################################################### #line 231 "lab1.Rnw" a=2+2 ################################################### ### chunk number 4: arith3 ################################################### #line 240 "lab1.Rnw" a ################################################### ### chunk number 5: arith4 ################################################### #line 290 "lab1.Rnw" x=5 y=2 z1=x*y ## no output z2=x/y ## no output z3=x^y ## no output z2 z3 ################################################### ### chunk number 6: arith5 ################################################### #line 307 "lab1.Rnw" z3=2*x^y ################################################### ### chunk number 7: arith6 ################################################### #line 315 "lab1.Rnw" A=3 C=(A+2*sqrt(A))/(A+5*sqrt(A)); C ################################################### ### chunk number 8: arith7 ################################################### #line 322 "lab1.Rnw" C=A+2*sqrt(A)/A+5*sqrt(A) ################################################### ### chunk number 9: help1 eval=FALSE ################################################### ## #line 516 "lab1.Rnw" ## help.search("sin") ################################################### ### chunk number 10: chlor1 ################################################### #line 535 "lab1.Rnw" Light=c(20,20,20,20,21,24,44,60,90,94,101) rmax=c(1.73,1.65,2.02,1.89,2.61,1.36,2.37,2.08,2.69,2.32,3.67) ################################################### ### chunk number 11: chlor2 ################################################### #line 562 "lab1.Rnw" plot(Light,rmax) ################################################### ### chunk number 12: chlorfig1 ################################################### #line 573 "lab1.Rnw" h = rev((1:6)/6) xr = seq(0,0.9,length=20) xpos = 1.2 op = par(xpd=TRUE,mar=c(0,0,0,5)) plot(0:1,range(h),type="n",axes=FALSE,ann=FALSE) points(xr,rep(h[1],20),pch=1:20) text(xpos,h[1],"pch: point type",adj=1) ##palette(gray((0:19)/19)) palette(rainbow(20)) points(xr,rep(h[2],20),col=1:20,pch=16) palette("default") text(xpos,h[2],"col: point color",adj=1) points(xr,rep(h[3],20),cex=seq(0.01,2,length=20)) text(xpos,h[3],"cex: point size",adj=1) text(xr,rep(h[4],20),c(letters[1:5],LETTERS[1:5],0:9)) text(xpos,h[4],"text",adj=1) ##text(seq(0.1,0.9,length=20),rep(0.6,20),letters[1:20],cex=seq(0.01,2,length=20)) nl = 6 nlsp = 0.1 lend = 0.95 ##segments(seq(0,0.9,length=nl),rep(h[5],2*nl), ## seq(1/nl,1,length=nl),rep(h[5],2*nl), ## want to go from 0 to lend, in nl segments, ## using a fraction fr of the space for interspaces ## each segment + space takes up lend/nl ## fr = 0.7 seg1 = seq(0,by=lend/nl,length=nl) seg2 = seq(lend/nl,to=lend,by=lend/nl)-(lend*(1-fr)/nl) segments(seg1,rep(h[5],nl), seg2, rep(h[5],nl), lty=1:nl,lwd=3) text(xpos,h[5],"lty: line type",adj=1) nv = 10 segments(seq(0,1/(1+nlsp),length=nv),rep(h[6],nv), seq(0.05,0.95,length=nv),rep(h[6],nv), lwd=1:10) text(xpos,h[6],"lwd: line width",adj=1) par(op) ################################################### ### chunk number 13: chlorfit1 ################################################### #line 637 "lab1.Rnw" fit = lm(rmax~Light) ################################################### ### chunk number 14: chlorfit2 ################################################### #line 663 "lab1.Rnw" summary(fit) ################################################### ### chunk number 15: chlorfit3 ################################################### #line 682 "lab1.Rnw" abline(fit) ################################################### ### chunk number 16: chlorfit4 ################################################### #line 691 "lab1.Rnw" plot(Light,rmax) abline(fit) ################################################### ### chunk number 17: chlorfit5 ################################################### #line 701 "lab1.Rnw" coef(fit) ################################################### ### chunk number 18: chlorfit6 ################################################### #line 711 "lab1.Rnw" names(fit) ################################################### ### chunk number 19: chlorfit7 ################################################### #line 717 "lab1.Rnw" fit$coefficients ################################################### ### chunk number 20: chlorscript1 eval=FALSE ################################################### ## #line 848 "lab1.Rnw" ## source("c:/temp/Intro1.R") ################################################### ### chunk number 21: chlorscript2 ################################################### #line 859 "lab1.Rnw" X=read.table("ChlorellaGrowth.txt",header=TRUE) ################################################### ### chunk number 22: chlorscript3 ################################################### #line 874 "lab1.Rnw" Light=X[,1] rmax=X[,2] ################################################### ### chunk number 23: ################################################### #line 895 "lab1.Rnw" X=read.table("ChlorellaGrowth.txt",header=TRUE) Light=X[,1] rmax=X[,2] logLight=log(Light) op <- par(cex=1.5,cex.main=0.9) plot(logLight,rmax, xlab="Log light intensity (uE/m2/s)", ylab="Maximum growth rate rmax (1/d)",pch=16) title(main="Data from Fussmann et al. (2000)") fit=lm(rmax~logLight) summary(fit) abline(fit) rcoef=round(coef(fit),digits=3) text(3.7,3.5,paste("rmax=",rcoef[1],"+",rcoef[2],"log(Light)")) par(op) ################################################### ### chunk number 24: eval=FALSE ################################################### ## #line 953 "lab1.Rnw" ## par(mfrow=c(2,3)) ################################################### ### chunk number 25: eval=FALSE ################################################### ## #line 1005 "lab1.Rnw" ## install.packages("plotrix") ################################################### ### chunk number 26: eval=FALSE ################################################### ## #line 1010 "lab1.Rnw" ## install.packages(c("ellipse","plotrix")) ################################################### ### chunk number 27: eval=FALSE ################################################### ## #line 1020 "lab1.Rnw" ## install.packages("plotrix",repos=NULL) ################################################### ### chunk number 28: eval=FALSE ################################################### ## #line 1042 "lab1.Rnw" ## ## TO DO: ignore packages? (weaver) ## r1 <- system("grep \"require(\" chap[0-9].Rnw chap[0-9][0-9].Rnw | sed -e 's/^.*require(\\([^),]*\\).*/\\1/'",intern=TRUE) ## r2 <- system("grep \"library(\" chap[0-9].Rnw chap[0-9][0-9].Rnw | sed -e 's/^.*library(\\([^),]*\\).*/\\1/'",intern=TRUE) ## r3 <- c(r1,r2) ## r3 <- unique(sort(r3[-grep("\\\\",r3)])) ## i1 <- installed.packages() ## omitpkgs <- rownames(i1)[!is.na(i1[,"Priority"])] ## omitpkgs <- c(omitpkgs,"Hmisc","weaver","pkg") ## r4 <- r3[!(r3 %in% omitpkgs)] ## ## OVERRIDE: add chron and gtools/gdata ## r4 <- c("adapt","bbmle","chron","coda","ellipse","emdbook","gplots","gtools","gdata", ## "MCMCpack","odesolve","plotrix","R2WinBUGS","reshape","rgl","scatterplot3d") ## cat(r4,"\n",fill=50) ################################################### ### chunk number 29: ################################################### #line 1126 "lab1.Rnw" initialsize=c(1,3,5,7,9,11) ################################################### ### chunk number 30: eval=FALSE ################################################### ## #line 1131 "lab1.Rnw" ## initialsize=read.table("c:/temp/initialdata.txt") ################################################### ### chunk number 31: ################################################### #line 1140 "lab1.Rnw" (finalsize=initialsize+1) (newsize=sqrt(initialsize)) ################################################### ### chunk number 32: ################################################### #line 1152 "lab1.Rnw" initialsize^2 ################################################### ### chunk number 33: ################################################### #line 1173 "lab1.Rnw" 1:8 ################################################### ### chunk number 34: ################################################### #line 1182 "lab1.Rnw" rep(3,5) ################################################### ### chunk number 35: ################################################### #line 1187 "lab1.Rnw" rep(1:3,3) ################################################### ### chunk number 36: ################################################### #line 1192 "lab1.Rnw" rep(1:3,each=3) ################################################### ### chunk number 37: ################################################### #line 1198 "lab1.Rnw" rep( c(3,4),c(2,5) ) ################################################### ### chunk number 38: ################################################### #line 1235 "lab1.Rnw" z=c(1,3,5,7,9,11) z[3] ################################################### ### chunk number 39: ################################################### #line 1244 "lab1.Rnw" z[2:5] ################################################### ### chunk number 40: ################################################### #line 1253 "lab1.Rnw" z[c(1,2,5)] ################################################### ### chunk number 41: ################################################### #line 1259 "lab1.Rnw" z[1]=12 ################################################### ### chunk number 42: ################################################### #line 1264 "lab1.Rnw" z[c(1,3,5)]=c(22,33,44) ################################################### ### chunk number 43: ################################################### #line 1304 "lab1.Rnw" x = 1.999999 x x-2 x=1.9999999999999 x x-2 ################################################### ### chunk number 44: ################################################### #line 1320 "lab1.Rnw" a=1 b=3 c=ab) c d ################################################### ### chunk number 45: ################################################### #line 1356 "lab1.Rnw" x=1:5 (b=(x<=3)) ################################################### ### chunk number 46: ################################################### #line 1368 "lab1.Rnw" a = 1:3 b = 2:4 a==b a=b a==b ################################################### ### chunk number 47: ################################################### #line 1404 "lab1.Rnw" a=c(1,2,3,4) b=c(1,1,5,5) (a3) (a3) ################################################### ### chunk number 48: ################################################### #line 1426 "lab1.Rnw" X=read.table("ChlorellaGrowth.txt",header=TRUE) Light=X[,1] rmax=X[,2] lowLight = Light[Light<50] lowLightrmax = rmax[Light<50] lowLight lowLightrmax ################################################### ### chunk number 49: ################################################### #line 1475 "lab1.Rnw" Light[Light<50 & rmax <= 2.0] rmax[Light<50 & rmax <= 2.0] ################################################### ### chunk number 50: ################################################### #line 1504 "lab1.Rnw" x = c(first=7,second=5,third=2) names(x) x["first"] x[c("third","first")] ################################################### ### chunk number 51: ################################################### #line 1532 "lab1.Rnw" (X=matrix(1:6,nrow=2,ncol=3)) ################################################### ### chunk number 52: ################################################### #line 1544 "lab1.Rnw" (A=matrix(1:9,nrow=3,ncol=3,byrow=TRUE)) ################################################### ### chunk number 53: eval=FALSE ################################################### ## #line 1550 "lab1.Rnw" ## matrix(1,nrow=10,ncol=10) ################################################### ### chunk number 54: ################################################### #line 1557 "lab1.Rnw" matrix(rep(1:2,4),nrow=2) ################################################### ### chunk number 55: eval=FALSE ################################################### ## #line 1586 "lab1.Rnw" ## A=matrix(0,nrow=3,ncol=4) ## data.entry(A) ################################################### ### chunk number 56: ################################################### #line 1624 "lab1.Rnw" (C=cbind(1:3,4:6,5:7)) ################################################### ### chunk number 57: ################################################### #line 1630 "lab1.Rnw" (D=rbind(1:3,4:6)) ################################################### ### chunk number 58: ################################################### #line 1645 "lab1.Rnw" A[2,2:3] (B=A[2:3,1:2]) ################################################### ### chunk number 59: ################################################### #line 1652 "lab1.Rnw" (first.row=A[1,]) (second.column=A[,2]) ################################################### ### chunk number 60: ################################################### #line 1661 "lab1.Rnw" (A[1,1]=12) ################################################### ### chunk number 61: ################################################### #line 1666 "lab1.Rnw" (A[1,]=c(2,4,5)) ################################################### ### chunk number 62: ################################################### #line 1676 "lab1.Rnw" which(A==8,arr.ind=TRUE) ################################################### ### chunk number 63: ################################################### #line 1695 "lab1.Rnw" L = list(A=x,B=y,C=c("a","b","c"))