Документ взят из кэша поисковой машины. Адрес оригинального документа : http://herba.msu.ru/shipunov/school/biol_240/20160302.r
Дата изменения: Wed Mar 2 22:21:53 2016
Дата индексирования: Sun Apr 10 07:28:58 2016
Кодировка:
m <- c("L","S","XL","XXL","S","M","L")
w <- c(69, 68, 93, 87, 59, 82, 72)
x <- c(174, 162, 188, 192, 165, 168, 172)
sex <- c("male","female","male","male","female","male","male")
d <- data.frame(weight=w, height=x, size=m, sex=sex)
rownames(d) <- c("Rick", "Amanda", "Peter", "Alex", "Kathy", "Ben", "George")
str(d)

d[d$sex == "female",]
d[d$sex == "female" | d$height < 170 ,]
d[d$sex == "female" & d$height < 170 ,]
d[d$sex == "female" & d$height < 165 ,]
d[d$sex == "female" & d$height <= 165 ,]
d[d$sex == "female" & d$height >= 165 ,]

sort(x)
rev(sort(x))
d[order(d$height),]
d[order(d$sex, d$height),]

salary <- c(21, 19, 27, 11, 102, 25, 21)
mean(salary)
median(salary)
sort(salary)
median(1:3)
median(1:4)
fivenum(salary)
boxplot(salary)
summary(salary)
d$salary <- salary

head(trees)
sapply(trees, mean)
sapply(trees, median)

# sapply(d, median) # error!
sapply(d[, c("weight","height","salary")], median)
numbers <- c("weight","height","salary")
sapply(d[,numbers], median)

t.sex <- table(sex)
t.sex[which.max(t.sex)]
names(t.sex[which.max(t.sex)])

var(salary)
sd(salary)
sqrt(var(salary))
IQR(salary)
sapply(trees, sd)
100*sapply(trees, sd)/sapply(trees, mean)

Sum <- function(a, b)
{
a+b
}
Sum(2, 3)

CV <- function(x)
{
100 * sd(x) / mean(x)
}
CV(salary)
CV(trees$Volume)
CV(trees$Height)
sapply(trees, CV)
sapply(d[,numbers], CV)
# fix(CV) # interactive!
sapply(d[,numbers], CV)

hist(salary)
hist(trees$Height)
plot(density(trees$Height))

err <- read.table("http://ashipunov.info/data/errors.txt", h=T, sep="\t")
str(err)
summary(err)