-
Notifications
You must be signed in to change notification settings - Fork 0
/
How_to_import_data_set.R
46 lines (32 loc) · 1.11 KB
/
How_to_import_data_set.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# How to import a data set
library(MASS)
data(AirPassengers)
AirPassengers
plot(AirPassengers)
# In statistics, a histogram is a graphical representation of
# the distribution of data. It is an estimate of the probability
# distribution of a continuous variable
hist(AirPassengers)
#with shading
hist(AirPassengers, density=20)
#with specific number of bins
hist(AirPassengers, density=20, breaks=20)
# proportion, instead of frequency
# also specifying y-axis
hist(AirPassengers, density=20, breaks=-3:3,
ylim=c(0,.5), prob=TRUE)
# overlay normal curve with x-lab and ylim
# colored normal curve
m<-mean(AirPassengers)
std<-sqrt(var(AirPassengers))
hist(AirPassengers, density=20, breaks=20, prob=TRUE,
xlab="x-variable", ylim=c(0, 0.7),
main="normal curve over histogram")
curve(dnorm(x, mean=m, sd=std),
col="darkblue", lwd=2, add=TRUE)
# hist(AirPassengers) is an object
# names(uh) will show all of its components
uh<-hist(AirPassengers)
plot(uh, ylim=c(0, 40), col="lightgray",
xlab="", main="Histogram of AirPassengers")
text(uh$mids, uh$counts+2, label=c(uh$counts))