Professional Documents
Culture Documents
https://cran.r- https://download1.rstudio.or
project.org/bin/windows g/desktop/windows/RStudio
/base/R-3.6.1-win.exe -1.2.1335.exe
Outline
1. Intro to Basic
2. Create a Vector
3. Create a Matrix
4. Create a Data Frame
5. Create an Array
6. Plot the data using ggplot2
NOW, OPEN YOUR R STUDIO
APPLICATION!
1. Intro to Basic
Project analysis slide 3
• Arithmetic with R
• R can be used as a simple calculator: subtraction (-), addition (+),
multiplication (*), division (/), exponentiation (^), modulo (%%)
• Expression of variable
Ex: my_var = “Hello World” or my_var <- “Hello World”
number_1 = 6
number_2 = 4
addition_num = number_1 + number_2
• How to print variable? Just type the variable into the console or use
command print()
• Basic data types in R: numeric, integers, logical, character
• How to check? Use command function class()
2. Create a Vector
Project analysis slide 3
• You can create a vector with the combine function c()
Ex: numeric_vector = c(3,4,5)
string_vector = c(“a”,”b”,”c”)
boolean_vector = c(TRUE, FALSE)
• You can create a vector name with function names()
Ex: names(numeric_vector) = string_vector
3. Create a Matrix
Project analysis slide 3
• Create a matrix with function matrix(data = NA, nrow = 1, ncol = 1,
byrow = FALSE, dimmnames = NULL)
Example:
mdat <- matrix(data = c(1,2,3,4), nrow = 2, ncol = 2, byrow = TRUE,
dimnames = list(c(“row1”,”row2”),c(“col1”,”col2”))
• You can create a matrix name with function rownames() and
colnames()
• Matrix usually can be used for looping calculations
4. Create a Data Frames
list(...)
6. Data Plot using ggplot2
Project analysis
1. Install packages
slide 3
install.packages(“tidyverse”)
install.packages(“readxl”) #package to import excel file
3. Let’s start to plot (Tips: The data must be form as data frames)
library(ggplot2)
plot.df = ggplot(data = data.excel, aes(x = wind, y= direction)) + geom_line() #line
graphs
plot.df1 = ggplot(data = data.excel, aes(x = time, y= temperature)) + geom_histogram() #bar
graphs
6. Data Plot using ggplot
Project analysis
1. Install packages
slide 3
install.packages(“tidyverse”)
install.packages(“readxl”) #package to import excel file
3. Let’s start to plot (Tips: The data must be form as data frames)
library(ggplot2)
plot.df = ggplot(data = data.excel, aes(x = wind, y= direction)) + geom_line() #line
graphs
plot.df1 = ggplot(data = data.excel, aes(x = time, y= temperature)) + geom_histogram() #bar
graphs
Thank You