R BASICS
R basic tutorials serve as introductory guides providing fundamental knowledge and practical insights into using the R programming language
INSTALLATION AND FIRST STEPS
R installation is done by downloading and installing the program from the official website. The first steps include getting familiar with the RStudio or R GUI interface and learning the basic syntax
How to install R and RStudio?
R GUI R STUDIO
Check which R version is running
R.version R.version.string getRversion()
How to update R and RStudio?
R GUI RStudio
RStudio themes
Operators
<- + - * / > < & |
DATA TYPES
In R, data types include numeric (integer, decimal), character (text), logical (true/false), complex and raw. Each type has specific characteristics and operations that allow you to manipulate and analyze data in a variety of ways in R
Data types
Numeric Character Logic Complex Raw
Convert objects to numeric with as.numeric()
as.numeric()
Convert objects to character with as.character()
as.character()
WORKING DIRECTORY AND WORKSPACE
In R, the working directory refers to the location in the file system where R looks for and stores files by default while the workspace stores variables and objects to maintain continuity of work between sessions
Workspace
rm() ls() save.image() save() saveRDS() load() readRDS() history()
Working directory
getwd() setwd() dir() list.files() file.create() file.remove() file.copy() file.path() file.info()
FUNCTIONS AND PACKAGES
Functions are reusable blocks of code that perform specific tasks. Packages are sets of functions, data and documentation that extend the functionality of R
Help
? help() help.start() help.search() apropos() RSiteSearch() vignette()
How to install packages ?
install.packages() library()
Create functions
R basics
Warning and error messages
message() warning() stop()
PRINTING VALUES
These functions are used to display results in the console. They help in the visualization and understanding of the generated information, being useful for inspecting data, displaying calculation results or facilitating the communication of results
The print() function
print()
Print and concatenate with cat()
cat()
Print formatted values
sprintf()
FUNCTIONS RELATED WITH TIME
R provides a number of functions to obtain the system date and time, which can be useful in various situations to manage runtimes and other processes