WEEK 1
Arithmatic
> 1+2
Create an R Object
> X <- c(5,5.5,6,6,6,6.5,6.5,6.5,6.5,7,7,8,8,9)
Table Function
> table()
Example: table(X)
Bar Plot
> plot(table(X))
WEEK 2
Data Frame a Table
> data.frame(table(work.hours))
Storing a Table's Frequencies with the freq Function
> freq <- table(work.hours)
Sum of The Frequency
> sum(freq)
A sequence of relative frequencies
> sum(freq/sum(freq))
The cumulative relative frequency is the accumulation of previous relative
frequencies.
Using the cumsum function:
> cumsum(freq/sum(freq))
Setting Working Directory
Change R's Working Directory: Right click on R Icon, Properties, change Start In path.
Check Working Directory
> getwd()
Reading of files in the CSV format
> ex.1 <- read.csv("ex1.csv")
Table the data of a specific column
> table(flower.data$Sepal.Width)
Plot a table of data of a specific column
>plot(table(flower.data$Sepal.Width))
, WEEK 3
Histogram
> hist(ex.1$height)
Sum of a specific column
> sum(ex.1$height)
The sum of the cumulative frequency, of a table of data for a specific column
> cumsum(table(ex.1$height))
Finding Quartiles
Use either the summary() or quartile() commands. However summary() is easiest.
Creating a boxplot
> boxplot(c(1,11.5,6,7.2,4,8,9,10,6.8,8.3,2,2,10,1))
Boxplot of a specific data column
> boxplot(ex.1$height)
Summary of a data column
> summary(ex.1$height)
R Function for mean
> mean(x)
R Function for median
> median(x)
Mean of a column
> mean(ex.1$height)
Medium of a column
> median(ex.1$height)
The Length Command (counts the number of observations)
> length(x)
Assign mean to an object
> x.bar <- mean(x)
Finding deviation
> x - x.bar
Computation of the squares of the deviations
> (x - x.bar)^2
Variance
> sum((x - x.bar)^2)/(length(x)-1)
or
> var(x)
Standard Deviation
> sqrt(sum((x - x.bar)^2)/(length(x)-1))
or
> sd(x)
WARNING: use the var() and sd() R commands only if you have all the data from a sample.