print("Hello World!")
print("Hello World!", quote = FALSE)
print(paste("Hello","World","!"))
$ R - start the R program
> q() - quit the R program
> help("topic") - help facility similar to the man facility of unix
> ?"topic" - help facility similar to the man facility of unix
> source("file.R") - execute commands stored in file.R
> install.packages("package_name")
> require(package_name)
> library(package_name)
> library(pacman)
> pacman::p_load(package_name)
You can use pacman to install packages
> detach(package_name)
> p_unload(package_name)
> p_unload(all)
Native package can't be loaded or unloaded with pacman
Pacman is a package, you should install it first
iris
plot(iris)
x <- iris[,1]
x
summary(x)
require(arules)
discretize(x)
To use discretize you neet to import the arules package
> install.packages(arules)
> require(arules)
table(discretize(x))
discretize(x, breaks = 10)
table(discretize(x, breaks = 10))
discretize(x, method = "interval", breaks = 3)
table(discretize(x, method = "interval", breaks = 3))
irisDisc <- discretizeDF(iris)
head(irisDisc)
irisDisc <- discretizeDF(iris, default = list(method = "interval", breaks = 2, labels = c("small", "large")))
head(irisDisc)
irisDiscB <- discretizeDF(iris, methods = list(
Petal.Length = list(method = "frequency", breaks = 3, labels = c("short", "medium", "long")),
Petal.Width = list(method = "frequency", breaks = 2, labels = c("narrow", "wide"))
))
head(irisDiscB)
set.seed(1234) # for reproducibility
x <- rnorm(10) # standard normal
x
To use standardize you neet to import the robustHD package
> install.packages(arules)
> require(arules)
require(robustHD)
standardize(x) # mean and sd
summary(x)
summary(standardize(x))
sd(x)
sd(standardize(x))
plot(iris$Species)
plot(iris$Petal.Length)
plot(iris$Species, iris$Petal.Width)
plot(iris$Petal.Length, iris$Petal.Width)
plot(iris)
plot(iris$Petal.Length, iris$Petal.Width,
col = "#cc0000",
pch = 19,
main = "Iris: Petal Length vs. Petal Width",
xlab = "Petal Length",
ylab = "Petal Width"
)
plot(cos, 0, 2*pi)
plot(exp, 1, 5)
plot(dnorm, -3, +3)
barplot(mtcars$gear)
We need a table with frequencies for each category.
barplot(table(mtcars$gear))
hist(iris$Sepal.Length)
# Put graphs in 3 rows and 1 column
par(mfrow = c(3,1))
# Histograms for setosa
hist(iris$Petal.Width [iris$Species == "setosa"],
xlim = c(0,3),
breaks = 9,
main = "Petal Width for Setosa",
xlab = "",
col = "red"
)
# Histograms for versicolor
hist(iris$Petal.Width [iris$Species == "versicolor"],
xlim = c(0,3),
breaks = 9,
main = "Petal Width for Versicolor",
xlab = "",
col = "green"
)
# Histograms for virginica
hist(iris$Petal.Width [iris$Species == "virginica"],
xlim = c(0,3),
breaks = 9,
main = "Petal Width for Virginica",
xlab = "",
col = "blue"
)