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:
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
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.
Write a short paragraph on various R-objects and describe the linear hierarchical difference between them.
die <- c(1, 2, 3, 4, 5, 6) die ##gives output for the function c
is.vector(die) ## gives binary response to the call function vector five <- 5 five ## 5
is.vector(five) ## gives if the function five is true or false length(five) ## gives the output for the five length(die) ## gives output for the line of code for die int <- 1L text <- “ace” int <- c(1L, 5L) text <- c(“ace”, “hearts”) ## 6 die <- c(1, 2, 3, 4, 5, 6) die typeof(die) ## “double” int <- c(-1L, 2L, 4L) int ## outputs the integers
typeof(int) ## outputs the types of integer sqrt(2)^2 - 2 text <- c(“Hello”, “World”) text ## gives the output of text hello world
typeof(text) ## this will be “character”
typeof(“Hello”) ## this will be “character” 3 > 4 ## FALSE because 4 >3 logic <- c(TRUE, FALSE, TRUE) logic ##gives output for the statement
typeof(logic) ## “logical” output
typeof(F) ## “logical” output comp <- c(1 + 1i, 1 + 2i, 1 + 3i) comp ## using the comparision for complex numbers 1+1i 1+2i 1+3i
typeof(comp) ## “complex” is the type of numbers raw(3) ## 00 00 00
typeof(raw(3)) ## “raw” hand <- c(“ace”, “king”, “queen”, “jack”, “ten”) hand ## Outputs the decks in the cards being ace,queen, king, jack, ten”
typeof(hand) ## “character is the output m <- matrix(die, nrow =
2) m ## [,1] [,2] [,3] ## [1,] 1 3 5 ## [2,] 2 4 6 m <- matrix(die,
nrow = 2, byrow = TRUE) m ## [,1] [,2] [,3] ## [1,] 1 2 3 ## [2,] 4 5 6
ar <- array(c(11:14, 21:24, 31:34), dim = c(2, 2, 3)) ar ## , , 1 ##
## [,1] [,2] ## [1,] 11 13 ## [2,] 12 14 ## ## , , 2 ## ## [,1] [,2] ##
[1,] 21 23 ## [2,] 22 24 ## ## , , 3 ## ## [,1] [,2] ## [1,] 31 33 ##
[2,] 32 34 ## [,1] [,2]
## [1,]”ace” “spades” ## [2,] “king” “spades” ## [3,] “queen” “spades”
## [4,] “jack” “spades” ## [5,] “ten” “spades” hand1 <- c(“ace”,
“king”, “queen”, “jack”, “ten”, “spades”, “spades”, “spades”, “spades”,
“spades”)
matrix(hand1, nrow = 5) matrix(hand1, ncol = 2) dim(hand1) <- c(5, 2) hand2 <- c(“ace”, “spades”, “king”, “spades”, “queen”, “spades”, “jack”, “spades”, “ten”, “spades”)
matrix(hand2, nrow = 5, byrow = TRUE) matrix(hand2, ncol = 2, byrow =
TRUE) list1 <- list(100:130, “R”, list(TRUE, FALSE)) list1 ## [[1]]
## [1] 100 101 102 103 104 105 106 107 108 109 110 111 112 ## [14] 113
114 115 116 117 118 119 120 121 122 123 124 125 ## [27] 126 127 128 129
130 ## ## [[2]] ## [1] “R” ## ## [[3]] ## [[3]][[1]] ## [1] TRUE ## ##
[[3]][[2]] ## [1] FALSE card <- list(“ace”, “hearts”, 1) card ##
[[1]] ## [1] “ace” ## ## [[2]] ## [1] “hearts” ## ## [[3]] ## [1] 1 df
<- data.frame(face = c(“ace”, “two”, “six”),
suit = c(“clubs”, “clubs”, “clubs”), value = c(1, 2, 3)) df ## face suit
value ## ace clubs 1 ## two clubs 2 ## six clubs 3 typeof(df) ##
“list”
class(df) ## “data.frame”
str(df) ## ‘data.frame’: 3 obs. of 3 variables: ## $ face : Factor w/
3 levels “ace”,“six”,“two”: 1 3 2 ## $ suit : Factor w/ 1 level “clubs”:
1 1 1 ## $ value: num 1 2 3 df <- data.frame(face = c(“ace”, “two”,
“six”),
suit = c(“clubs”, “clubs”, “clubs”), value = c(1, 2, 3),
stringsAsFactors = FALSE) ## face suit value ## king spades 13 ## queen
spades 12 ## jack spades 11 ## ten spades 10 ## nine spades 9 ## eight
spades 8 ## seven spades 7 ## six spades 6 ## five spades 5 ## four
spades 4 ## three spades 3 ## two spades 2 ## ace spades 1 ## king clubs
13 ## queen clubs 12 ## jack clubs 11 ## ten clubs 10 deck <-
data.frame( face = c(“king”, “queen”, “jack”, “ten”, “nine”, “eight”,
“seven”, “six”, “five”, “four”, “three”, “two”, “ace”, “king”, “queen”,
“jack”, “ten”, “nine”, “eight”, “seven”, “six”, “five”, “four”, “three”,
“two”, “ace”, “king”, “queen”, “jack”, “ten”, “nine”, “eight”, “seven”,
“six”, “five”, “four”, “three”, “two”, “ace”, “king”, “queen”, “jack”,
“ten”, “nine”, “eight”, “seven”, “six”, “five”, “four”, “three”, “two”,
“ace”),
suit = c(“spades”, “spades”, “spades”, “spades”, “spades”, “spades”,
“spades”, “spades”, “spades”, “spades”, “spades”, “spades”, “spades”,
“clubs”, “clubs”, “clubs”, “clubs”, “clubs”, “clubs”, “clubs”, “clubs”,
“clubs”, “clubs”, “clubs”, “clubs”, “clubs”, “diamonds”, “diamonds”,
“diamonds”, “diamonds”, “diamonds”, “diamonds”, “diamonds”, “diamonds”,
“diamonds”, “diamonds”, “diamonds”, “diamonds”, “diamonds”, “hearts”,
“hearts”, “hearts”, “hearts”, “hearts”, “hearts”, “hearts”, “hearts”,
“hearts”, “hearts”, “hearts”, “hearts”, “hearts”), value = c(13, 12, 11,
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2,
1, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 13, 12, 11, 10, 9, 8, 7,
6, 5, 4, 3, 2, 1) )