dat <- data.frame(group1 = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2),
group2 = c(1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2),
x1 = c(3, 1, 4, 2, 5, 3, 2, 4, NA, 4, 5, 3),
x2 = c(4, NA, 3, 6, 3, 7, 2, 7, 5, 1, 3, 6),
x3 = c(7, 8, 5, 6, 4, NA, 8, NA, 6, 5, 8, 6))
# Descriptive statistics for x1
descript(dat$x1)
# Descriptive statistics for x1, print results with 3 digits
descript(dat$x1, digits = 3)
# Descriptive statistics for x1, convert value 4 to NA
descript(dat$x1, as.na = 4)
# Descriptive statistics for x1, print all available statistical measures
descript(dat$x1, print = "all")
# Descriptive statistics for x1, x2, and x3
descript(dat[, c("x1", "x2", "x3")])
# Descriptive statistics for x1, x2, and x3,
# listwise deletion for missing data
descript(dat[, c("x1", "x2", "x3")], na.omit = TRUE)
# Descriptive statistics for x1, x2, and x3,
# analysis by group1 separately
descript(dat[, c("x1", "x2", "x3")], group = dat$group1)
# Descriptive statistics for x1, x2, and x3,
# analysis by group1 separately, sort by variables
descript(dat[, c("x1", "x2", "x3")], group = dat$group1, sort.var = TRUE)
# Descriptive statistics for x1, x2, and x3,
# split analysis by group1
descript(dat[, c("x1", "x2", "x3")], split = dat$group1)
# Descriptive statistics for x1, x2, and x3,
# analysis by group1 separately, split analysis by group2
descript(dat[, c("x1", "x2", "x3")], group = dat$group1, split = dat$group2)
if (FALSE) {
# Write Results into a Excel file
descript(dat[, c("x1", "x2", "x3")], write = "Descript.xlsx")
result <- descript(dat[, c("x1", "x2", "x3")], output = FALSE)
write.result(result, "Descript.xlsx")
}
Run the code above in your browser using DataLab