This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
#creating vectors
a <-(c(2,5,6,7))
a
## [1] 2 5 6 7
b <-(c(1,0,9,8))
b
## [1] 1 0 9 8
c <- (c(6,5,8,3))
c
## [1] 6 5 8 3
#Combining all vectors
d <- c(a,b,c)
d
## [1] 2 5 6 7 1 0 9 8 6 5 8 3
#matrix formation
mat <- matrix(d, byrow=TRUE, nrow=3)
print(mat)
## [,1] [,2] [,3] [,4]
## [1,] 2 5 6 7
## [2,] 1 0 9 8
## [3,] 6 5 8 3
#Naming a matrix
rownames(mat) <-c("present", "absent", "on leave")
colnames(mat) <-c("mon", "tue", "wed", "thu")
mat
## mon tue wed thu
## present 2 5 6 7
## absent 1 0 9 8
## on leave 6 5 8 3
#calculate rowsum & colsum
row <- rowSums(mat)
row
## present absent on leave
## 20 18 22
col <- colSums(mat)
col
## mon tue wed thu
## 9 10 23 18
data <- mtcars
library(ggplot2)
ggplot(data=data)+
geom_point(mapping=aes(x=mpg,y=disp), col="#2D5A0C")
#Boxplot
p<-ggplot(data=data, aes(mpg, gear))
p
p+geom_boxplot()
## Warning: Continuous x aesthetic
## ℹ did you forget `aes(group = ...)`?
p+geom_boxplot() + coord_flip()
## Warning: Continuous x aesthetic
## ℹ did you forget `aes(group = ...)`?
p+geom_boxplot(notch=TRUE, col="#0C115A")
## Warning: Continuous x aesthetic
## ℹ did you forget `aes(group = ...)`?
## Notch went outside hinges
## ℹ Do you want `notch = FALSE`?
#histogram
q<-ggplot(data=data, aes(disp))
q+
geom_histogram()+
geom_freqpoly()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.