3 # Basic plot x <- 1:10 y <- x*x "> 3 # Basic plot x <- 1:10 y <- x*x "> 3 # Basic plot x <- 1:10 y <- x*x ">
# R is an open source statistical programming language.
# R is used for data cleaning, analysis & visualization.
# RStudio: An IDE / Interface for R.
# R is case sensitive
# Data types in R : Char/String - Numeric: Double/Int - Logical - Factor
# Basic Mathematics
1+1
sqrt(4)
3 ^ 2
log(100)
exp(3)
8 / 0 # infinity
# Value assigment in R
x1 = as.integer(5)
x1 <- 5L
x2 <- 5
x3 <- "a"
x4 <- TRUE
x5 <- 2.02
typeof(x5)
# Check for specific datatype
is.numeric(x1)
is.character(x3)
is.logical(x4)
#Removing an object from the environment
rm(x1)
#Clear the entire environment
rm(list = ls())
# Methods for printing output in R
x <- 4
x
(x <- 4)
print(x)
paste("The value of x is",x) #print a string and variable together
sprintf("The value of x is %.2f", x) #use the C print function
#Vector operations
#R operations are vectorized: occur in parallel
x <- 1:4
x <- c(1,2,3,4)
y <- 6:9
z1 <- x + y
z2 <- x / y
#vectorized logical comparisons
x <- 1:5
x > 3
# Basic plot
x <- 1:10
y <- x*x
help(plot)
plot(x, y, type = "b", pch = 19,
col = "red", xlab = "xValues", ylab = "yValues", main = "Basic plot")
#View a dataset in R
library(datasets) # load the library for datasets
help(datasets) # view help
library(help = "datasets")
#load a dataset
data(iris)
head(iris,2) # show the first 2 rows of a dataset
dim(iris)
#Example for for loop - if statement
for (x in iris$Sepal.Length){
if(x > 6)
print(x)
}