Basic concepts Flashcards
(116 cards)
When was R created and which language inspired it?
R was created in 1996 and was inspired by S Language.
What’s the main purpose of R?
It’s an statistical environment for data analysis and graphs creation.
What are the 3 main characteristics of R?
- Free and open source
- Intepreted language (instead of compiled)
- Object oriented (everything is an object in R)
What’s the current version of R? (as of Feb 2021)
4.0.4
What are the 4 possible IDEs mentioned by Dr. Fernando in the class?
- R Studio Desktop
- R Studio Cloud (create an account first)
- Google Collab
- Emacs + ESS (highly recommended)
What is the Working Directory? When do I need to set it? How to set it?
It’s the folder to which R will be redirected. All imported and exported files will be in this directory. It’s very important to set it before I start working.
I can set it with the function setwd(“/home/paulojardim/pasta”)
I can get it with the function getwd( )
What function do I use to list all the objects created in an environement?
ls( )
It returns a vector of character strings giving the name of the objects.
What is R Workspace?
It’s the place in memory where the variables (objects) are saved. It’s all that was created during a sessios, saved in RAM memory. We can save it in a .Rdata file if they were produced after a long calculation. But the ideal is saving the code itself.
What function should I use to generate random numbers of a uniform distribution? What are its arguments and which are mandatory? What’s the default for the not mandatory?
runif (n, min = 0, max = 1)
n = number of observations we want to return. It’s the mandatory argument
min and max are the limits, they are not mandatory and assume 0 and 1 if not provided.
e.g. runif(5) returns 5 random numbers between 0 and 1
Do I need to name the arguments when I call a funtion in R? What about order?
No, I don’t neeed to name them. But if I don’t name them I need to respect the order. If I name them I can use in any order.
How can I easily see the arguments of a function?
I can call args( ) function.
e.g. args( sample ) returns:
function (x, size, replace = FALSE, prob = NULL)
How do I know what are the mandatory arguments of a function?
When I see the args of a function, the ones that don’t have a default value are mandatory:
e.g. in sample() function below, x and size are mandatory
function (x, size, replace = FALSE, prob = NULL)
What is the techincal name of “…” and when should I use it in my function?
It’s called ellipsis and I use basically in two situations:
- When it makes sense for a function receiving an undefined number of arguments (e.g. print function). Then I can transform the arguments in a list:
- arguments = list(…)*
2. When I need to receive arguments to pass to a generic function.
What function should I use to concatenate strings?
paste(“string”, “string2”, “string3” , …… )
How can I easily see the documentation of a function?
I can use ?function or help(function).
They both return the same thing
Within the documentation, what’s the session that tells me about what the function returns?
The Value session.
What function returns a list of functions/objects containing a expression?
apropos(“mod”)
What function returns a list of functions containing a word in any part of their documentation?
help.search(“geo”)
How can I see what are the loaded/attached packages at the moment and what are their code paths in my computer?
- search()* - lists the loaded/attached packages
- searchpaths()* - lists their paths in my computer
What is the most basic way of getting access to R official documentation?
- Run R from the terminal by executing “R” command
- In R prompt, execute help.start( ). It will launch a local webserver and open the html manuals and documentation.
Introduction to R and The R Language Definition are the main ones.
Worthy reading!
What are the 7 packages that are loaded/attached automatically when we run R?
- base
- utils
- stats
- graphics
- grDevices
- datasets
- methods
How do I load an installed package in R?
I need to run function library() providing the name of the package.
How do I install a new package in R?
Run function install.packages(“package_name”)
How do I verify if the installed packages need updates?
Execute function packageStatus()