Well this was the class that i took some year back, a three day R studio Tutorial classes.
Things We will Study today
- Intro To R
- How to use Rstudio
- Mean
- Median
- Mode
- Range
- Quartile Deviation
- Standard Deviation
To View the Datasets available by default
library(help="datasets")
So Basically We are using a Dataset Cars which is by default present in the RStudio which basically consists of 50 rows:
nrow(cars)
## [1] 50
and 2 columns:
ncol(cars)
## [1] 2
head() gives the first 6 rows of the dataset so that we can make an idea about the dataset
head(cars)
## speed dist
## 1 4 2
## 2 4 10
## 3 7 4
## 4 7 22
## 5 8 16
## 6 9 10
To access a particular column
cars$speed
## [1] 4 4 7 7 8 9 10 10 10 11 11 12 12 12 12 13 13 13 13 14 14 14 14
## [24] 15 15 15 16 16 17 17 17 18 18 18 18 19 19 19 20 20 20 20 20 22 23 24
## [47] 24 24 24 25
Similarly,
cars$dist
## [1] 2 10 4 22 16 10 18 26 34 17 28 14 20 24 28 26 34
## [18] 34 46 26 36 60 80 20 26 54 32 40 32 40 50 42 56 76
## [35] 84 36 46 68 32 48 52 56 64 66 54 70 92 93 120 85
For mean
mean(cars$dist)
## [1] 42.98
Median, run :
median(cars$dist)
## [1] 36
Quantile , run :
quantile(cars$dist)
## 0% 25% 50% 75% 100%
## 2 26 36 56 120
Variance , run :
var(cars$dist)
## [1] 664.0608
Standard Deviation , run :
sd(cars$dist)
## [1] 25.76938
To do all the things we have done at once we use a function summary()
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
GRAPHS
We can also embed plots, for example:
A histogram of the speed of the Cars using hist() function
Scatterplot
plot(cars,xlab="Speed",ylab = "Distance",main = "Scatter plot of Speed and distance covered")
Barplot Similarly for barplot
barplot(cars$dist)
Note that the echo = FALSE
parameter was added to the code chunk to prevent printing of the R code that generated the plot.