a = rnorm(20) a[1:10] a[-2] seq(-2,2,by=0.2) rep(1,10) a = c(1:12) rep(a, 3) mymatrix = matrix(a,3,4,byrow=T) mymatrix = matrix(a,3,4) apply(mymatrix,1,mean) apply(mymatrix,2,sum) apply(mymatrix,1,max) mymatrix[1:2, ] mymatrix[-1,] mymatrix[,2:4] dim(mymatrix) # write your own function myfunc =function(a){b=mean(a);c=sd(a);d=a+2;outcome=list(b,c,d);return(outcome)} a=rnorm(10) myfunc(a) one sample t test # loop function x= c(1:10) for (i in 1:10){x[i]=x[i]+10} x #plot plot(x,y) #scatterplot plot(x,y,type="l") # line plot (x,y,type="b") # both points and line plot(x,y,pch="+") # plotting character plot(x,y,type="l",lty=3,col=2) # line type and color plot(x,y, xlab="mid term test score",ylab="final test score", main="relation between midterm and final scores") pairs(mymatrix) # pairwise scatter plot coplot(a~b|c) # plot a vs b at given level of c