1 Important Notes

1.1 Comment

  1. Always make comments in your code. This will be important for future reviews.
# Coment

1.2 Help

2 Don’t forget the help commands. Every official package has documented functions.

2.1 When you know the name of the function, use: ?function

?mean

2.2 Performing a search on all package installed on your system.

??mean

2.3 Search for information in function help pages and vignettes for all CRAN packages.

RSiteSearch("mean")

1.3 Variable types

The most common types of variables to be defined in R

1.3.1 Numeric

vet <- c(-1,0,1)  
vet
## [1] -1  0  1
class(vet) # The function `class` return the class of the vector
## [1] "numeric"
vet <- c(-1.5, 0.593, 1)
class(vet)
## [1] "numeric"

1.3.2 Date

today <- Sys.Date()
today
## [1] "2021-04-19"
class(today)
## [1] "Date"

1.3.3 Character

  • Defined as text and has no numeric value
vet <- as.character(c(-1,0,1))
vet
## [1] "-1" "0"  "1"
class(vet)
## [1] "character"
  • Provincial acronyms of South Africa
texto <- c("EC","FS","GT","NL","LP","MP","NC","NW","WC")
texto
## [1] "EC" "FS" "GT" "NL" "LP" "MP" "NC" "NW" "WC"
class(texto)
## [1] "character"

1.3.4 Factor

  • Both numeric and character variables can be made into factors, but a factor’s levels will always be character values
vet <- factor(c(-1.5, 0.593, 1))
vet
## [1] -1.5  0.593 1    
## Levels: -1.5 0.593 1
class(vet)
## [1] "factor"
texto <- factor(c("EC","FS","GT","NL","LP","MP","NC","NW","WC"))
texto
## [1] EC FS GT NL LP MP NC NW WC
## Levels: EC FS GT LP MP NC NL NW WC
class(texto)
## [1] "factor"