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:
# 'Vector - most basic object of R'
# Vector contains only homogenous objects
# List can contain hetrogenous objects
# 'Five types of atomic classes of objects :
# 1. numeric
# 2. integer
# 3. complex
# 4. character
# 5. logical
# numeric vector
x <- c(0.4,1.5)
x # Auto printing
## [1] 0.4 1.5
print(x) # explicit printing
## [1] 0.4 1.5
attributes(x)
## NULL
# creates numeric vector of length 4 and initial value as 0
x1 <- vector(mode = "numeric",
length = 4)
x1
## [1] 0 0 0 0
# character vector
y <- c('a','b')
y
## [1] "a" "b"
y1 <- vector(mode = "character",
length = 5)
y1
## [1] "" "" "" "" ""
# logical vector
z <- c(T,F)
z
## [1] TRUE FALSE
z1 <- vector(mode = "logical",
length = 3)
z1
## [1] FALSE FALSE FALSE
# complex vector
w <- c(1+2i, 3+7i)
w
## [1] 1+2i 3+7i
w1 <- vector(mode = "complex",
length = 4)
w1
## [1] 0+0i 0+0i 0+0i 0+0i
# integer vector
u <- c(1L,3L)
v <- c(3:10)
u
## [1] 1 3
v
## [1] 3 4 5 6 7 8 9 10
u1 <- vector(mode = "integer",
length = 5)
u1
## [1] 0 0 0 0 0
# vector coercion
a <- c(1,'a') # coerced to character
a
## [1] "1" "a"
b <- c(T,1) # coerced to numeric
b
## [1] 1 1
c <- c(T,'a') # coerced to character
c
## [1] "TRUE" "a"
d <- c(2L,3) # coerced to numeric
d
## [1] 2 3
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.