Professional Documents
Culture Documents
1. x < - c(1, 2, 5, 1, 4, 9, 4)
y<-x
[1] 1, 2, 5, 1, 4, 9, 1
Returns 1 element
Positive Integers
Returns 1 element
vec(1:4)
vec[-1:4]
vec[3, 4, 5]
Blanc Spaces
Names
Names
Logical
Logical
Subset Notation
2D Data Structures
2D Data Structures
Separate
dimensions
with a comma
df[ ?, ?]
Which rows to
Which columns
include
To include
Positive integers
lst[[1]] returns
Lists
lst[[1]] returns
Lst[[1]][2] returns 2
$
The most common syntax for subsetting lists and data
frames
returns
$
Equivalent to
lst[[‘alpha’]]
$
Logical comparison
c(1, 2, 3, 4, 5) > 3
Logical comparison
Returns
c(1, 2, 3, 4, 5) > 3 c(F, F, F, T, T)
Logical comparison
Returns
c(1, 2, 3, 4, 5) > 3 c(F, F, F, T, T)
c(1, 2, 3, 4, 5) >= 3
Logical comparison
Returns
c(1, 2, 3, 4, 5) > 3 c(F, F, F, T, T)
Returns
c(1, 2, 3, 4, 5) >= 3 c(F, F, T, T, T)
Logical comparison
Returns
c(1, 2, 3, 4, 5) > 3 c(F, F, F, T, T)
Returns
c(1, 2, 3, 4, 5) >= 3 c(F, F, T, T, T)
c(1, 2, 3, 4, 5) == 3
Logical comparison
Returns
c(1, 2, 3, 4, 5) > 3 c(F, F, F, T, T)
Returns
c(1, 2, 3, 4, 5) >= 3 c(F, F, T, T, T)
Returns
c(1, 2, 3, 4, 5) == 3 c(F, F, T, F, F)
Logical comparison
Returns
c(1, 2, 3, 4, 5) > 3 c(F, F, F, T, T)
Returns
c(1, 2, 3, 4, 5) >= 3 c(F, F, T, T, T)
Returns
c(1, 2, 3, 4, 5) == 3 c(F, F, T, F, F)
c(1, 2, 3, 4, 5) != 3
Logical comparison
Returns
c(1, 2, 3, 4, 5) > 3 c(F, F, F, T, T)
Returns
c(1, 2, 3, 4, 5) >= 3 c(F, F, T, T, T)
Returns
c(1, 2, 3, 4, 5) == 3 c(F, F, T, F, F)
Returns
c(1, 2, 3, 4, 5) != 3 C(T, T, F, T, T)
Logical comparison
Returns
c(1, 2, 3, 4, 5) > 3 c(F, F, F, T, T)
Returns
c(1, 2, 3, 4, 5) >= 3 c(F, F, T, T, T)
Returns
c(1, 2, 3, 4, 5) == 3 c(F, F, T, F, F)
Returns
c(1, 2, 3, 4, 5) != 3 C(T, T, F, T, T)
c(1, 2, 3, 4, 5) = 3
Logical comparison
Returns
c(1, 2, 3, 4, 5) > 3 c(F, F, F, T, T)
Returns
c(1, 2, 3, 4, 5) >= 3 c(F, F, T, T, T)
Returns
c(1, 2, 3, 4, 5) == 3 c(F, F, T, F, F)
Returns
c(1, 2, 3, 4, 5) != 3 C(T, T, F, T, T)
Returns
Error!! = sign is the same as
c(1, 2, 3, 4, 5) = 3
<-
%in% tests whether the object on the left is a member of the group
on the right.
Boolean operators
Boolean operators
Define :
x <- 3
x<2&x>0
Boolean operators
Define :
x <- 3
x<2&x>0
FALSE
Boolean operators
Define :
x <- 3
x<2|x>0
Boolean operators
Define :
x <- 3
x<2|x>0
FALSE | TRUE
TRUE
Boolean operators
Define :
x <- 3
x <- 3
xor(FALSE, TRUE)
TRUE
Logical Subsetting
Combining logical tests with subsetting is a very powerful technique!
x[indices]
Logical Subsetting
Logical Subsetting
NA Behavior
NA Behavior
NA Behavior
NA Behavior
Logical Subsetting