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
vstring<-c('a','b','c')
vstring
## [1] "a" "b" "c"
headings<-list(NULL, c("a","b","c"))
headings
## [[1]]
## NULL
##
## [[2]]
## [1] "a" "b" "c"
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=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]
m3[1,]
## a b c
## 1 2 3
m3[,2]
## [1] 2 5 2
m3[3,2]
## b
## 2
a<- list(aa=1, bb=2, cc=3)
a
## $aa
## [1] 1
##
## $bb
## [1] 2
##
## $cc
## [1] 3
a$aa
## [1] 1
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$score
## [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 55")}
## [1] " a is more than 55"
mylist <- c(55, 66, 77, 88, 99)
for (value in mylist){
print(value)
}
## [1] 55
## [1] 66
## [1] 77
## [1] 88
## [1] 99
a < 100
## [1] TRUE
while (a <500){
a <- a + 100
print(a)
}
## [1] 166
## [1] 266
## [1] 366
## [1] 466
## [1] 566
a
## [1] 566
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.