Cat without quotation is used to display variables. Ex. a=3, cat(a), 3 is displayed
● typeof → show what kind of variable it is
OPERATIONS FOR NUMERIC VARIABLES
● + → addition
● - → subtraction
● * → multiplication
● %/% → floor division: without decimals (rounded)
● %%==0 → modulus: check if remainder of a division is 0
● %%# → modulus: divide numbers by # and extract the remainder of the division
READLINE
● readline(”TEXT”) → Ask for information from the user of the script. Always
character variable
To convert readline variables into other variables:
● variable = as.numeric(variable)
● variable = as.integer(variable)
● variable = as.character(variable)
● variable = as.logic = (variable)
COMMANDS FOR CHARACTER VARIABLES
● nchar(text_variable) → number of characters in text_variable
● toupper(text_variable) → put in uppercase
● tolower(text_variable) → put in lowercase
, ● gsub(“st”,”street”, text) → change “st” for “street” in text
● trimws(text_variable) → delete unnecessary spaces
● gsub(“ “,””,name of variable) → to delete all spaces in a variable
● grepl(“word”, text_variable) → check if a word is in the variable
Transform word to lower case first
● substr(text_variable, number, number) → Show the characters in position of first
number until the second number
● paste0(variable 1, variable 2) → paste two variables together
CONDITIONAL STATEMENTS
If (condition a) {
if it is false, then…
}else if (condition b)
….
}else{
}
Final else is optional and always without condition
For conditions:
● a > b → greater than
● a < b → less than
● a == b → equal to
● a & b → a and b
● a|b → a or b
LOOPS