PROGRAMMING:
PYTHON
SUMMARY +
ASSIGNMENTS
@ECOsummaries
→ 20% discount
1
, Introduction to R
Chapter 1
Math:
Addition: +
Subtraction: -
Multiplication: *
Division: /
Exponentiation: ^
Modulo: %%
Variable assignment:
my_var <- 4
my_fruit <- my_oranges + my_apples
Data types:
Numerics: decimal values 4.5
Integers: natural numbers 4
Logical: boolean values (TRUE or FALSE)
Characters: text / string
Class(‘something’) = gives data type of variable
Chapter 2
Vectors:
Combine function: c(1, 10, 49) or c(‘a’, ‘b’, ‘c’)
Assign names: names(roulette_vector) <- (‘Monday’, etc.)
Adding vectors: A_vector = c(1, 2, 3) and B_vector = c(4, 5, 6) → total_vector = c(5, 7, 9)
Sum: total_poker <- sum(poker_vector) → sums all values inside of the vector
Comparing: total_poker > total_roulette → TRUE
Vector selection: poker_vector <- c(140, -50, 20) with names ‘Mon’, ‘Tue’, ‘Wed’
poker_vector[1] = 140
poker_vector[c(1,3)] = (140, 20)
poker_vector[1:3] = (140, -50, 20)
poker_vector[c(‘Monday’, ‘Wednesday’)] = (140, 20)
Comparison:
Comparison operators: <, >, <=, >=, ==, !=
selection vector <- poker_vector > 0 → will give TRUE or FALSE for each day
poker_vector[selection_vector] → will give only the amounts on TRUE days
2