# S-PLUS Lecture 3

8 pages
9 views

View again

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Share
Description
S-PLUS Lecture 3. Jaeyong Lee. Factors. A factor and a category are special types of vector, normally used to hold a categorical variable in many statistical functions. Category is deprecated. Factor has a class attribute, hence it is adapted to generic function mechanism. Session: Factors.
Transcript
S-PLUS Lecture 3Jaeyong LeeFactors
• A factor and a category are special types of vector, normally used to hold a categorical variable in many statistical functions.
• Category is deprecated.
• Factor has a class attribute, hence it is adapted to generic function mechanism.
• Session: Factorscitizen <- c(“uk”, “us”, “no”,”au”,”uk”,”us”, “us”,”no”,”au”)citizenf <- factor(citizen)attributes(citizenf)unclass(citizenf) # This is the same as category(citizen)table(citizenf)citizeno <- ordered(citizen, levels=“us”,”au”,”no”,”uk”)ordered(cut(geyser\$duration, breaks=0:6),levels=1:6)income <- c(10, 20, 15, 12, 17, 13, 22, 9,14)tapply(income, citizenf, mean)Arrays
• A matrix is a two dimensional collection of data and an array is a generalization of matrix.
• A dimension vector of an array is an attribute of the array representing the dimension.
• S arrays use column-major order: the first index moves fastest, and the last slowest.
• Session: Arrays 1 z <- 1:150 a <- array(z,dim=c(3,5,10)) dim(z) <- c(3,5,10)z[1,1,1]z[2,1,1]matrix(1:6,nrow=2,ncol=3)z <- matrix(1:6,nrow=2, ncol=3, byrow=T)z[1,]z[,2]Session: Arrays 2x <- matrix(0,nc=5,nr=5); xi <- matrix(1:5,5,2); ix[i] <- 1; xmatrix(1:6, 3, 2)*matrix(1:6*2, 3, 2)X <- matrix(1:6,3,2)y <- 1:3t(X) %*% ySession: Array 3A <- matrix(c(1,1,2,3),2,2)b <- c(2,5)solve(A,b)diag(rep(1,2))solve(A,diag(rep(1,2)))A[2, ] <- c(2,7) chol(A)t(chol(A)) %*% chol(A)Session: Array 4eg <- eigen(A)eg\$valueseg\$vectors t(eg\$vectors) %*% diag(eg\$values) %*% eg\$vectorsX <- matrix(1:6,3,2)s <- svd(X)ss\$u %*% diag(s\$d) %*% t(s\$v)
Related Search
Similar documents

View more...