Introduction to Basics of R: Getting Started in R and RStudio
Start your Base R on your laptop or computer
Basically, R and Rstudio are the same software, however RStudio is an Integrated Development Environment (IDE) wherein you can run, edit
commands and see the results simaltanouesly. Therefore whatever commands that you run in Base R and RStudio will give the same results. Quickly
run some mathematical operations in Base R and move to RStudio
# is used for adding comments
# <- is considered as equal to sign in R
#Let us run command
print("Welcome to R!")
## print() is a function. it tells computer to do something
## “Welcome to R!” is an argument
the information function needs to run to give output
# Perform basic mathematical operationAdd12+6substract12-6#multiplying 12 by 612*6#divide 12 by 612/6
# In Similar fashion you can do all the mathematical calculations.
Variable defination in R
# Variable defination in R # We are assigning value 3 to variable x and value 5 to variable y. Print the value of x and yx <- 3y <- 5
x
y
z <- x + yzn <- z
# assigning value to my_varmy_var <- 42my_varmy_banana <- 6my_bananamy_apple <- 5my_applemy_chikoo <- 5my_chikoomy_pin <- 3my_pin
# adding fruitsmy_basket <- my_banana + my_apple + my_chikoo + my_pinmy_basketavg_fruit <- (my_banana + my_apple + my_chikoo + my_pin)/4avg_fruit
Basic data types in R
## Numerics ## Character Text ## Boolean values
## Class of the data> x <- 5.5> x[1] 5.5> y <- 5>> z<- 3 + 2i> z[1] 3+2i> ## # The quotation marks indicate that the variable is of type character> my_character <- " universe"> my_character[1] " universe"> class(x)[1] "numeric"> class(y)[1] "numeric"> class(z)[1] "complex"> class( my_character)[1] "character">> my_character <- "1"> my_logical <- TRUE> my_logical <- FALSE> ## What is the class of this variable?>> my_character42 <- "forty-two"> class(my_character42)[1] "character"