It will store a value in a variable
a<-2
a
## [1] 2
mean-mean(x) pakage-tools..install pakage ## Function , comment,insatll packages ctl+alt+i–insert chunk cntrl+R for executing your script
X<-c(1:20)## this is simple comment
X
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
install.packages(“ggplot2”)
X<-c(1,2,3,5:10,NA)
sd(X)
sd(X,na.rm=TRUE)
sd(X,TRUE)
sd(na.rm=TRUE,X)
sd(TRUE,X)
sd(na.rm=TRUE,X)
sd(TRUE,X=X)
sd(TRUE,X=X) 1)create 5 dimentional vector of values 4,7,3,2,5 as x
x<-c(4,7,3,2,5)
2)add 2 with x and assign the value to y
y<-x+2
3)find the mean and sd of y
mean(y)
## [1] 6.2
sd(y)
## [1] 1.923538
4)create another variable z as combination 2,3
z<-c(2,3)
5)add x and z
x+z
## Warning in x + z: longer object length is not a multiple of shorter object
## length
## [1] 6 10 5 5 7
r class has five basic or “atomic” clases of objects: charecter numeric integer complex logical(true/false)
x<-1
class(x)
## [1] "numeric"
x<-1L
class(x)
## [1] "integer"
x<-(1:20)
length(x)
## [1] 20
x<-c(1:20,"rekha")
x
## [1] "1" "2" "3" "4" "5" "6" "7" "8"
## [9] "9" "10" "11" "12" "13" "14" "15" "16"
## [17] "17" "18" "19" "20" "rekha"
x<-as.factor(x)
class(x)
## [1] "factor"
x<-(1:20)
x<-as.character(x)
class(x)
## [1] "character"
x<-20:50
x
## [1] 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
## [24] 43 44 45 46 47 48 49 50
x<-c(20:50,50:100)
x
## [1] 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
## [18] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 50 51 52
## [35] 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
## [52] 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
## [69] 87 88 89 90 91 92 93 94 95 96 97 98 99 100
rm(list=ls())
x<-c(0.5, 0.6)
x
## [1] 0.5 0.6
y<-c(TRUE,2)
y
## [1] 1 2
x<-seq(1,6,0.5)
x
## [1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
class(x)
## [1] "numeric"
x<-as.integer(x)
x
## [1] 1 1 2 2 3 3 4 4 5 5 6
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
m<-1:10
m
## [1] 1 2 3 4 5 6 7 8 9 10
dim(m)<-c(2,5)
m
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 3 5 7 9
## [2,] 2 4 6 8 10
y<-20:29
x<-1:10
z<-50:59
x<-c(1,2,3)
y<-c(2,3,4,5)
cbind(x,y)
## Warning in cbind(x, y): number of rows of result is not a multiple of
## vector length (arg 1)
## x y
## [1,] 1 2
## [2,] 2 3
## [3,] 3 4
## [4,] 1 5
x<-list(c(1,2,3),c("rekha","karam"))
x
## [[1]]
## [1] 1 2 3
##
## [[2]]
## [1] "rekha" "karam"
x[1]
## [[1]]
## [1] 1 2 3
x[2]
## [[1]]
## [1] "rekha" "karam"
x[[c(1,2)]]
## [1] 2
x[[c(2,2)]]
## [1] "karam"
x<-factor(c("yes","yes","yes"))
x
## [1] yes yes yes
## Levels: yes
class(x)
## [1] "factor"
args(factor)
## function (x = character(), levels, labels = levels, exclude = NA,
## ordered = is.ordered(x), nmax = NA)
## NULL
x<-factor(c("yes","yes","yes","NA"))
class(x)
## [1] "factor"
x
## [1] yes yes yes NA
## Levels: NA yes
y<-factor(x,exclude="NA")
## Warning in as.vector(exclude, typeof(x)): NAs introduced by coercion
y
## [1] yes yes yes NA
## Levels: NA yes
y=factor(x)
y
## [1] yes yes yes NA
## Levels: NA yes
table(x)
## x
## NA yes
## 1 3
x<-c("yes","yes","no")
table(x)
## x
## no yes
## 1 2
y<-factor(c("yes","no","yes","no"),labels=c("2","1"))
y
## [1] 1 2 1 2
## Levels: 2 1
args(factor)
## function (x = character(), levels, labels = levels, exclude = NA,
## ordered = is.ordered(x), nmax = NA)
## NULL
y<-factor(c("yes","no","yes","no"),labels=c("1","2"))
y
## [1] 2 1 2 1
## Levels: 1 2
l<-list(c("athanu","karam"),c(2,3,4,5,19,2,7,5,5))
l
## [[1]]
## [1] "athanu" "karam"
##
## [[2]]
## [1] 2 3 4 5 19 2 7 5 5
## check the class of second element of the list.
class(l[[2]])
## [1] "numeric"
l[[c(2,4)]]
## [1] 5
x<-as.factor(l[[1]])
x
## [1] athanu karam
## Levels: athanu karam
l<-list(c("athanu","karam"),c(2,3,4,5,19,2,7,5,5))
table(l[2])
##
## 2 3 4 5 7 19
## 2 1 1 3 1 1