Assigning operator

it will store a value in variable

a<-2
a
## [1] 2

rmarkdown cheatsheet

functions=>

function combine values into vector.

c(123)
## [1] 123
 x <-c("karam", "ram","anu")

class(x)gives type of x. ##coments=>

a<-1#comment

install packages

click on tools and install package. ##control+alt+i=>to insert chunk. cntrl+R=> to execute selected chunk.

>install.package("ggplot")#this is inline r code which does not execute.

TO GET the lines typed in new line type double space after every line.

this
there
where

to get help from R,type

help(mean)
## starting httpd help server ... done

NA in function for finding sd

x<-c(1,2,3,NA)
sd(x,na.rm=TRUE)
## [1] 1
sd(x,TRUE)
## [1] 1
sd(na.rm = TRUE,x)
## [1] 1
sd(TRUE,x=x)
## [1] 1

place to turn

.r-help@r-project.org
.stackoverflow
.github issue ## create one 5 dimensional vector of values4,7,3,2,5 as ‘x’

x<-c(4,7,3,2,8)
x
## [1] 4 7 3 2 8

add 2 with x and assign the value to y

y<-x+2
y
## [1]  6  9  5  4 10

find the mean and sd of y

mean(y)
## [1] 6.8
sd(y)
## [1] 2.588436

create another variable z as combination of 2,3

z<-c(2,3,NA,NA,NA)

add x and z

x+z
## [1]  6 10 NA NA NA

## objects R has five basicor ‘atomic’ class of objects: .character
.numeric(real numbers)
.integer
.complex .logical

x<-1
class(x)
## [1] "numeric"
x<-1L
class(x)
## [1] "integer"
?class

attributes

.names,dim names
.dimensions
.class
.length
.other user-defined atrributes/meta data

x<-c(1:20,"karam")
length(x)
## [1] 21
x<-1
print(x)
## [1] 1
x<-5
x
## [1] 5
x<-c(1:20)
x
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20

creating vectors

the c()function can be used to create vectors of object

x<-c(0.5,0.6)
x
## [1] 0.5 0.6
x<-c(TRUE ,FALSE)
x
## [1]  TRUE FALSE

MIXING objects

y<-c(1.7,"a")
y
## [1] "1.7" "a"
c(TRUE,2)
## [1] 1 2
x<-1:6.0
class(x)
## [1] "integer"
x<-seq(1,6,0.5)
class(x)
## [1] "numeric"
x<-as.integer(x)
x
##  [1] 1 1 2 2 3 3 4 4 5 5 6

matrices

matrix(1:20,nrow=2)
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,]    1    3    5    7    9   11   13   15   17    19
## [2,]    2    4    6    8   10   12   14   16   18    20
args(matrix)
## function (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) 
## NULL
matrix(1:20,nrow=2,byrow=TRUE)
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,]    1    2    3    4    5    6    7    8    9    10
## [2,]   11   12   13   14   15   16   17   18   19    20

``` ## cbinding and rbinding

x<-1:10
x
##  [1]  1  2  3  4  5  6  7  8  9 10
y<-20:29
y
##  [1] 20 21 22 23 24 25 26 27 28 29
cbind(x,y)
##        x  y
##  [1,]  1 20
##  [2,]  2 21
##  [3,]  3 22
##  [4,]  4 23
##  [5,]  5 24
##  [6,]  6 25
##  [7,]  7 26
##  [8,]  8 27
##  [9,]  9 28
## [10,] 10 29
rbind(x,y)
##   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## x    1    2    3    4    5    6    7    8    9    10
## y   20   21   22   23   24   25   26   27   28    29

list`

x<-list(c(1,2,3),c("sujit","karam"))
x
## [[1]]
## [1] 1 2 3
## 
## [[2]]
## [1] "sujit" "karam"
x[2]
## [[1]]
## [1] "sujit" "karam"
x
## [[1]]
## [1] 1 2 3
## 
## [[2]]
## [1] "sujit" "karam"
x[[c(1,2)]]
## [1] 2
x[[c(2,1)]]
## [1] "sujit"
x<-factor(c("yes","yes","no","yes"))
x
## [1] yes yes no  yes
## Levels: no yes
class(x)
## [1] "factor"
x<-factor(x)
x
## [1] yes yes no  yes
## Levels: no yes
args(factor)
## function (x = character(), levels, labels = levels, exclude = NA, 
##     ordered = is.ordered(x), nmax = NA) 
## NULL
y<-factor(x,exclude="NA")
## Warning in as.vector(exclude, typeof(x)): NAs introduced by coercion
y
## [1] yes yes no  yes
## Levels: no yes
table(y)
## y
##  no yes 
##   1   3
args(factor)
## function (x = character(), levels, labels = levels, exclude = NA, 
##     ordered = is.ordered(x), nmax = NA) 
## NULL