# NOT RUN {
# -------------------------------------------
# one or two numeric or categorical variables
# -------------------------------------------
# create data frame, mydata, to mimic reading data with rad function
# mydata contains both numeric and non-numeric data
# X has two character values, Y is numeric
n <- 15
X <- sample(c("Group1","Group2"), size=n, replace=TRUE)
Y <- round(rnorm(n=n, mean=50, sd=10),3)
mydata <- data.frame(X,Y)
rm(X); rm(Y)
# Analyze the values of numerical Y
# Calculate n, mean, sd, skew, kurtosis, min, max, quartiles
SummaryStats(Y)
# short name
ss(Y)
# output saved for later analysis
s <- ss(Y)
# view full text output
s
# view just the outlier analysis
s$out_outliers
# list the names of all the components
names(s)
# Analyze the values of categorical X
# Calculate frequencies and proportions, totals, chi-square
SummaryStats(X)
# Only a subset of available summary statistics
ss.brief(Y)
ss.brief(X, label.max=3)
# Reference the summary stats in the object: stats
stats <- ss(Y)
my.mean <- stats$mean
# Get the summary statistics for Y at each level of X
# Specify 2 decimal digits for each statistic displayed
SummaryStats(Y, by=X, digits.d=2)
# ----------
# data frame
# ----------
# Analyze all variables in data frame mydata at once
# Any variables with a numeric data type and 4 or less
# unique values will be analyzed as a categorical variable
SummaryStats()
# Analyze all variables in data frame mydata at once
# Any variables with a numeric data type and 7 or less
# unique values will be analyzed as a categorical variable
SummaryStats(n.cat=7)
# analyze just a subset of a data frame
mydata <- Read("Employee", in.lessR=TRUE, quiet=TRUE)
SummaryStats(c(Salary,Years))
# ----------------------------------------
# data frame different from default mydata
# ----------------------------------------
# variables in a data frame which is not the default mydata
# access the breaks variable in the R provided warpbreaks data set
# although data not attached, access the variable directly by its name
data(warpbreaks)
SummaryStats(breaks, by=wool, data=warpbreaks)
# Analyze all variables in data frame warpbreaks at once
SummaryStats(warpbreaks)
# ----------------------------
# can enter many types of data
# ----------------------------
# generate and enter integer data
X1 <- sample(1:4, size=100, replace=TRUE)
X2 <- sample(1:4, size=100, replace=TRUE)
SummaryStats(X1)
SummaryStats(X1,X2)
# generate and enter type double data
X1 <- sample(c(1,2,3,4), size=100, replace=TRUE)
X2 <- sample(c(1,2,3,4), size=100, replace=TRUE)
SummaryStats(X1)
SummaryStats(X1, by=X2)
# generate and enter character string data
# that is, without first converting to a factor
Travel <- sample(c("Bike", "Bus", "Car", "Motorcycle"), size=25, replace=TRUE)
SummaryStats(Travel)
# }
Run the code above in your browser using DataLab