Some hints for HW1. If you have a plot that is huge, meaning it takes a ton of memory, try saving it as a jpeg or take a screenshot of it as a png or something, so it is not such a big file and then just drag it into Word and save your hw as a pdf if you'd like. You can also use knitr or Rmarkdown or latex if you'd like but you certainly don't need to, as Word is perfectly fine. As arguments to plot(), pch is useful to change the plotting symbol, and col for plotting color. type="n" is to set up the plot but not plot the points. points(x,y) adds the points to the current plot. cex is for character size. lines(x,y) connects the dots and adds them to the current plot. lty adjusts the line type. x = 1:5; y = c(3,2,4,3,4) plot(x,y) plot(x,y,type="n") points(x,y,pch=".") ## tiny dots points(x,y,pch=2) ## triangles plot(x,y,type="n"); points(x,y,pch=3) ## plus signs plot(x,y,type="n"); points(x,y,pch=3, col="blue") plot(x,y,type="n"); points(x,y,pch=y, col="blue") points(x,y,pch=as.character(x)) plot(x,y,pch=x, col="blue",cex=2); points(x,y,pch=as.character(x),cex=.7) lines(x,y,col="red",lty=3) runif(n) generates n pseudo-random uniform variables on [0,1]. x = runif(10000) y = runif(10000)*20-7 ## 10000 random uniforms on [-7,13]. plot(x,y) plot(x,y,pch=".") quantile(x,0.9); quantile(y,0.9) sort() sorts a vector, by default from smallest to largest. z = sort(y) z[1:5] z[9000] z = sort(y,decreasing=TRUE) ## to sort from biggest to smallest. z[1:5] ## Suppose we want to find sqrt(sum of 1/k^2.1), for k = 1, 2, 3, ..., n. n = 100000 x = rep(1,n) for (k in 2:n){ x[k] = x[k-1] + 1/k^2.1 } y = sqrt(x) ## Alternative way to do it: x = rep(1,n) for (k in 2:n){ x[k] = 1/k^2.1 } y = cumsum(x) z = sqrt(y) par(mfrow=c(1,2)) ## do this if you want two plots per page. plot(c(0,n),c(min(y),max(y)),type="n",xlab="k", ylab="sqrt{sum of 1/i^2.1 from i=1 to k}") points(1:n,y,pch=".") ## problems: the range of the y-axis is too big, ## and the labels on the axes are ugly. max(y) ## 1.249085 plot(c(0,n),c(1.248,1.2491),type="n",xlab="k", ylab="sqrt{sum of 1/i^2.1 from i=1 to k}") points(1:n,y,pch=".") ## didn't help enough. You have to zoom in a lot more here on the y-axis. plot(c(0,n),c(1.24905,1.249086),type="n",xlab="k", ylab="sqrt{sum of 1/i^2.1 from i=1 to k}") points(1:n,y,pch=".") ## problem: the labels on the axes are still ugly. plot(c(0,n),c(1.24905,1.249086),type="n",xlab="k", ylab=expression(sqrt(sum(frac(1,i^2.1),i==1, k)))) points(1:n,y,pch=".") abline(h=1.249085,lty=2) ## problems: the labels on both axes are still not great. plot(c(0,n/1000),c(1.24905,1.249086),type="n", xlab="k (thousands)",ylab="",cex.axis=.7) mtext(s=2,l=1.35, at = 1.249065, expression(sqrt(sum(frac(1,i^2.1),i==1, k)))) points(c(1:n)/1000,y,pch=".") abline(h=1.249085,lty=2) par(mfrow=c(1,1)) ## just one plot on the page plot(c(0,n/1000),c(1.24905,1.249086),type="n",xlab="k (thousands)",ylab="",cex.axis=.7) mtext(s=2,l=1.35, at = 1.249065, expression(sqrt(sum(frac(1,i^2.1),i==1, k)))) points(c(1:n)/1000,y,pch=".") abline(h=1.249085,lty=2)