https://posit.co/download/rstudio-desktop/
Reading up on the help files from official R website
help()
function and ?
help operator in
R provide access to the documentation pages for R functions, data sets,
and other objects, both for packages in the standard R distribution and
for contributed packages.File names should be meaningful and informative
Variable and function names should be lowercase
Let me begin by introducing basic math operations.
R data types are used to specify the kind of data that can be stored in a variable.
For effective memory consumption and precise computation, the right data type must be selected.
Each R data type has its own set of regulations and restrictions.
Basic data types in R can be divided into the following types:
numeric - (10.5, 55, 787)
integer - (1L, 55L, 100L, where the letter “L” declares this as an integer
complex - (9 + 3i, where “i” is the imaginary part)
character (a.k.a string) - (“k”, “R is exciting”, “FALSE”, “11.5”)
logical (a.k.a boolean) - (TRUE or FALSE)
?datasets()
df <- mtcars
df$mpg2 <- as.integer(df$mpg)
df$mpg3 <- as.numeric(df$mpg)
df <- as.data.frame(Titanic)
str(df)
## 'data.frame': 32 obs. of 5 variables:
## $ Class : Factor w/ 4 levels "1st","2nd","3rd",..: 1 2 3 4 1 2 3 4 1 2 ...
## $ Sex : Factor w/ 2 levels "Male","Female": 1 1 1 1 2 2 2 2 1 1 ...
## $ Age : Factor w/ 2 levels "Child","Adult": 1 1 1 1 1 1 1 1 2 2 ...
## $ Survived: Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
## $ Freq : num 0 0 35 0 0 0 17 0 118 154 ...
2 + 2 # addition
## [1] 4
5 - 4
## [1] 1
2 * 3
## [1] 6
8/3
## [1] 2.666667
# Plot data -------------------