Basic commands in S Plus or R language Jiquan Chen, UT, 8/28/2012 1) Database structure between SAS, Excel, R, etc. (about data, analysis, and graphics) 2) R free-ware: brief history from S programming 3) Introduction of basic comments Introduction of basic comments ls() # arrows up and down to retrieve previous commends quit() dir() Data() CO2, CO2[,2], dim(BOD) # case sensitive exit() # of a loop help() # for comments X=2 remove(x) x<-c(2:10) x=x*12 3:15 # as calculator 2.5*(3:15) #other operations on Page 40 runif(10) #random number generator for 10 numbers. Howa about a number between 0 and 100? runif (1)*100 c=c(1:20) mean(c) max (c) y=sqrt(c) #other functions can be found on Page 46 seq(-10, 10, by=2.5) #create a bin order () rank() rnorm(100) # generate 100 number following normal distribution; see other distributions on Page 49 gamma (0.2) Source(‘xxx’) # philosophical differences in programming Sink (“xxx”) matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) scan(‘test.prn’) #read data from a file plot(CO2[,4], CO2[,5]) # graphic capability plot(CO2[,4], CO2[,5], xlab = "", ylab="") plot(CO2[,4], CO2[,5], xlab = "CO2 Concentration", ylab="Uptake") plot(CO2[,4], CO2[,5], xlab = "CO2 Concentration", ylab="Uptake", type='l') plot(CO2) qqnorm(y, ylim, main = "Normal Q-Q Plot",xlab = "Theoretical Quantiles", ylab = "Sample Quantiles",plot.it = TRUE, datax = FALSE, ...) qqplot() boxplot() barplot() dotchart() pie() contour(x,y,z,v) interp(x,y,z) lines() history() library() methods("summary") help(package="Matrix") demo() demo(glm.vr) data() help.search("plot") Examples: library("sp") # add a new package from any open source Packages in library ‘C:/Program Files/R/R-2.14.1/library’: base boot The R Base Package Bootstrap Functions (originally by Angelo Canty for S) class Functions for Classification cluster Cluster Analysis Extended Rousseeuw et al. codetools Code Analysis Tools for R compiler The R Compiler Package datasets The R Datasets Package deldir Delaunay Triangulation and Dirichlet (Voronoi) Tessellation. foreign Read Data Stored by Minitab, S, SAS, SPSS, Stata, Systat, dBase, ... geoR Analysis of geostatistical data graphics The R Graphics Package grDevices The R Graphics Devices and Support for Colours and Fonts grid The Grid Graphics Package gstat spatial and spatio-temporal geostatistical modelling, prediction and simulation KernSmooth Functions for kernel smoothing for Wand & Jones (1995) lattice Lattice Graphics MASS Support Functions and Datasets for Venables and Ripley's MASS Matrix Sparse and Dense Matrix Classes and Methods methods Formal Methods and Classes mgcv GAMs with GCV/AIC/REML smoothness estimation and GAMMs by PQL nlme Linear and Nonlinear Mixed Effects Models nnet Feed-forward Neural Networks and Multinomial Log-Linear Models parallel Support for Parallel computation in R RandomFields Simulation and Analysis of Random Fields rpart Recursive Partitioning sp classes and methods for spatial data spacetime classes and methods for spatio-temporal data spatial Functions for Kriging and Point Pattern Analysis spatialCovariance Computation of spatial covariance matrices for data on rectangles spatstat Spatial Point Pattern analysis, model-fitting, simulation, tests splancs Spatial and Space-Time Point Pattern Analysis splines Regression Spline Functions and Classes stats The R Stats Package stats4 Statistical Functions using S4 Classes survival Survival analysis, including penalised likelihood. tcltk Tcl/Tk Interface tools Tools for Package Development utils The R Utils Package wavelets A package of funtions for computing wavelet filters, wavelet transforms and multiresolution analyses xts eXtensible Time Series zoo S3 Infrastructure for Regular and Irregular Time Series (Z's ordered observations)