This document contains a guide on the R studio commands and what the command is used for to create and work with mathematical operations, readline variables, character variables, conditional statements, loops, functions, arrays and vectors, data frames, merges, and all of the dplyr commands.
● cat(“ “) → display a sentence on the screen
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
● 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
Los beneficios de comprar resúmenes en Stuvia estan en línea:
Garantiza la calidad de los comentarios
Compradores de Stuvia evaluaron más de 700.000 resúmenes. Así estas seguro que compras los mejores documentos!
Compra fácil y rápido
Puedes pagar rápidamente y en una vez con iDeal, tarjeta de crédito o con tu crédito de Stuvia. Sin tener que hacerte miembro.
Enfócate en lo más importante
Tus compañeros escriben los resúmenes. Por eso tienes la seguridad que tienes un resumen actual y confiable.
Así llegas a la conclusión rapidamente!
Preguntas frecuentes
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
100% de satisfacción garantizada: ¿Cómo funciona?
Nuestra garantía de satisfacción le asegura que siempre encontrará un documento de estudio a tu medida. Tu rellenas un formulario y nuestro equipo de atención al cliente se encarga del resto.
Who am I buying this summary from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller dannaadelapaz03. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy this summary for 16,49 €. You're not tied to anything after your purchase.