Professional Documents
Culture Documents
package("ggplot2")
a=25
#---DATA OPERATORS
a+d
a
a*d
a/d
d^3
d^8
22 %% 7
22/7
22 %/% 7
3.8 %/% 2
e <<- 50
100 ->> f
f > e
e > f
e == f
d != e
d >= e
g=5
d >= g
X = TRUE
Y = FALSE
X & Y
X & X
Y & Y
X | Y
Y | X
Y | Y
!Y
Y
h <- 1:10
h
6 %in% h
15 %in% h
#---DATA TYPES
A = TRUE
B <- FALSE
C = 5
D = 5L
E = 8.5L
F = "R seems to be good!"
vtr[2]
vtr [2:3]
vtr [-1]
vtr[7] <- 15
vtr
ctrl+l
list1 <- c(1,3,5,7)
list2 <- c("Red", "Blue", "Green")
list3 <- c(list1, list2)
list3
ctrl+l
#----------------------------------------------------------------------------------
----------
#JUST TO PRINT AN ARRAY
#----------------------------------------------------------------------------------
----------
# Create two vectors of different lengths.
vector1 <- c(5,9,3)
vector2 <- c(10,11,12,13,14,15)
#----------------------------------------------------------------------------------
----------
#PRINT SELECTED ELEMENTS
#----------------------------------------------------------------------------------
----------
# Print the element in the 1st row and 3rd column of the 1st matrix.
print(result[1,3,1])
#----------------------------------------------------------------------------------
----------
#ADD TWO MATRIX
#----------------------------------------------------------------------------------
----------
# Create two vectors of different lengths.
vector1 <- c(5,9,3)
vector2 <- c(10,11,12,13,14,15)
#----------------------------------------------------------------------------------
----------
#FACTOR
#----------------------------------------------------------------------------------
----------
# Create a vector as input.
data <-
c("East","West","East","North","North","East","West","West","West","East","North")
print(data)
print(is.factor(data))
print(factor_data)
print(is.factor(factor_data))
#----------------------------------------------------------------------------------
----------
#DATA FRAME
#----------------------------------------------------------------------------------
----------
#----------------------------------------------------------------------------------
----------
#DECISION MAKING
#----------------------------------------------------------------------------------
----------
x <- 30L
if(is.integer(x)) {
print("X is an Integer")
}
#----------------------------------------------------------------------------------
----------
#DECISION MAKING
#----------------------------------------------------------------------------------
----------
x <- c("what","is","truth")
if("truth" %in% x) {
print("Truth is found the first time")
} else if ("truth" %in% x) {
print("truth is found the second time")
} else {
print("No truth found")
}
#----------------------------------------------------------------------------------
----------
#DECISION MAKING - SWITCH CASE
#----------------------------------------------------------------------------------
----------
switch(option,
"mean" = print(mean(vtr)),
"sum" = print(sum(vtr)),
print("Invalid Option")
)