we had some basic R commands and we explored R as a super calculator
2+3
## [1] 5
2/3
## [1] 0.6666667
Use rnorm to generate a few random numbers ~N(0,1):
rnorm(100)
## [1] 1.224752839 -0.211509437 0.710438234 0.453516374 -0.572447001
## [6] 0.421535132 0.536676069 -0.384082941 1.787063892 -0.332658462
## [11] -0.757946483 -0.159763366 0.442159041 0.779073768 0.839355305
## [16] -1.215309604 2.253626323 -1.142028534 -0.076112065 1.190816958
## [21] -1.685490122 0.694750446 1.162587670 2.017359540 0.406634678
## [26] 1.448881559 2.109212875 1.195003189 -0.579705604 -0.297615897
## [31] 0.386013534 1.084697106 0.593781491 -0.742106406 1.163684003
## [36] 0.384338366 -0.457214844 -0.661792572 0.473577578 -1.591513166
## [41] -0.632006175 1.503667522 -0.460898055 1.351555560 1.240189257
## [46] 1.385728376 -0.562381028 -0.190938391 -0.160912484 -0.287888040
## [51] 1.211272695 0.021625276 2.293053686 0.698753668 -0.649749822
## [56] -0.617965970 0.306648462 -1.110083565 0.087131320 -0.643355254
## [61] -0.863190464 -0.982348047 1.964438156 -1.757286640 -0.595188664
## [66] 1.328094872 -0.438485713 -0.400101764 -0.865263033 -0.135142212
## [71] -0.396984275 -0.227481058 -2.574886386 -0.635752815 -0.381724518
## [76] 1.348003613 -0.768024520 -0.387453841 0.401234999 -2.044107084
## [81] -1.940714392 0.556525858 -0.069012604 0.476393913 -0.940777305
## [86] 0.646157728 1.141335748 -0.550577770 2.035812580 -0.956112527
## [91] 0.947205153 0.923868657 -1.091924970 2.577934036 0.251314667
## [96] 0.008938974 -0.022691630 -0.422104619 -0.628083607 0.056449120
plot(rnorm(100))
we made the data Student255 Student (excel/csv/txt) file and imported in R.
student255 <- read.delim("~/comp Stats notes/student255.txt")
student255
## Student Height Drive Study Course Tutoring Sleeping
## 1 1 70.0 0.10 2 5 0 8.5
## 2 2 70.8 1.00 0 5 0 8.0
## 3 3 64.0 1.50 2 5 0 8.0
## 4 4 69.0 0.15 3 5 0 7.5
## 5 5 68.0 3.00 3 5 0 8.0
## 6 6 68.0 0.00 4 5 0 7.0
## 7 7 73.0 0.33 3 5 0 8.0
## 8 8 70.0 3.00 3 5 0 8.0
In case you want to see every single column seperately:
str(student255)
## 'data.frame': 8 obs. of 7 variables:
## $ Student : int 1 2 3 4 5 6 7 8
## $ Height : num 70 70.8 64 69 68 68 73 70
## $ Drive : num 0.1 1 1.5 0.15 3 0 0.33 3
## $ Study : int 2 0 2 3 3 4 3 3
## $ Course : int 5 5 5 5 5 5 5 5
## $ Tutoring: int 0 0 0 0 0 0 0 0
## $ Sleeping: num 8.5 8 8 7.5 8 7 8 8
Suppose you want to plot the Student versus Height graph
attach(student255)
plot(Height)
Here we inserted the “include = TRUE” option to make the figure visible.
Here are some different plot types
plot(Height) #plots scatter plot
hist(Height) #creates a histogram
barplot(Height) #creates a barplot
barplot(Height, main = "Height of the Students in inches", xlab = "Students", ylab = "Heights")
The line types for graph format are below 1. p= point 2. l= line 3. o= over plotted points & lines 4. b= points joined by lines 5. c= empty points joined by lines 6. s= staircase 7. h= vertical lines