R Markdown

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:

data<-c(1,2,3,4,5,6)
data
## [1] 1 2 3 4 5 6
#dfdsaff
vstring<-c('a','b','c')
vstring
## [1] "a" "b" "c"
#creating a list
headings<-list(NULL, c("a", "b","c"))
headings
## [[1]]
## NULL
## 
## [[2]]
## [1] "a" "b" "c"
#matrics: same concept like mathematics
m<-matrix(data,nrow = 2, ncol = 3, byrow= TRUE, dimnames=headings)
m
##      a b c
## [1,] 1 2 3
## [2,] 4 5 6
m2<-matrix(data,nrow = 2, ncol = 3, byrow= FALSE, dimnames=headings)
m2
##      a b c
## [1,] 1 3 5
## [2,] 2 4 6
m3<-matrix(data,nrow = 3, ncol = 2, byrow= TRUE)
m3
##      [,1] [,2]
## [1,]    1    2
## [2,]    3    4
## [3,]    5    6
m4<-matrix(data,nrow = 3, ncol = 3, byrow= TRUE, dimnames=headings)
## Warning in matrix(data, nrow = 3, ncol = 3, byrow = TRUE, dimnames = headings):
## data length differs from size of matrix: [6 != 3 x 3]
m4
##      a b c
## [1,] 1 2 3
## [2,] 4 5 6
## [3,] 1 2 3
#tO print out a specific element 
m4[1,]
## a b c 
## 1 2 3
m4[ ,2]
## [1] 2 5 2
m4[3,2]
## b 
## 2
#$ is used to access a specific element of the list
a<- list(aa=1, bb=2, cc=3)
a
## $aa
## [1] 1
## 
## $bb
## [1] 2
## 
## $cc
## [1] 3
years <- c(1980, 1985, 1990)
scores <- c(34, 44, 83)
df <- data.frame(years, scores)
df[,1]
## [1] 1980 1985 1990
df$years
## [1] 1980 1985 1990
df$scores
## [1] 34 44 83
View(df)
a <- 66 
if (a > 55){
  print("a is more than 55")} else{print("a is less than or equal to 55")}
## [1] "a is more than 55"
a
## [1] 66
a <-100
while(a < 500){
  a <-a + 100
  print(a)
}
## [1] 200
## [1] 300
## [1] 400
## [1] 500
a
## [1] 500

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.