Control/Ctrl + 1: Source editor (your script)
Control/Ctrl + 2: Console
Control/Ctrl + 3: Help
Control/Ctrl + 4: History
Control/Ctrl + 5: Files
Control/Ctrl + 6: Plots
Control/Ctrl + 7: Packages
Control/Ctrl + 8: Environment
Control/Ctrl + 9: Viewer
Tools > Keyboard Shortcuts Help (Alt + Shift + K)
<- (Alt + - )
%<% (Ctrl + Shift + M)
Comment or uncomment lines → Ctrl + Shift + C
Move Lines Up/Down → Alt+Up/Down
Delete Line → Ctrl+D
Select → Shift+[Arrow]
Select Word → Ctrl+Shift+Left/Right
Select to Line Start → Alt+Shift+Left
Select to Line End → Alt+Shift+Right
Run current line → Ctrl + Enter
Run current line (retain cursor position) → Alt+Enter
Run all lines of code → Ctrl + A + Enter
Clear Console → Ctrl+L
Restart the current R session → Ctrl + Shift + F10
Search the command history from the Console → Ctrl + [up arrow])
Quickly Find Files and Functions → Ctrl + .
Open Files → Ctrl+O
New File R Script → Ctrl+Shift+N
R Markdown
Additional
Bahasa pemrograman sekaligus software yang memungkinkan pengolahan data secara statistik (statistical computing) → But it’s more than that: supporting the whole data science flow + other purposes
source: https://www.storybench.org/getting-started-with-tidyverse-in-r
RStudio cheatsheet collections: https://www.rstudio.com/resources/cheatsheets/
Working Directory
getwd()setwd(directory_path)setwd(‘/run/media/DATA/myR/’)R.versionTambahan :
R Project An R project enables your work to be bundled in a portable, self-contained folder. Within the project, all the relevant scripts, data files, figures/outputs, and history are stored in sub-folders and importantly - the working directory is the project’s root folder.
Start Writing The Code + Help
# Print greeting
print("Welcome to R!")
[1] "Welcome to R!"
# Help
# ?thingstosearch
?print()
?print()
?cbind()
print("R is the coolest subject I've ever learned")
[1] "R is the coolest subject I've ever learned"
"R is the coolest subject I've ever learned"
[1] "R is the coolest subject I've ever learned"
# 'R is the coolest subject I've ever learned' #ERROR
Collections of functions written by R’s talented community of developers.
Memperkaya fungsionalitas R dalam mengolah data.
contoh: tidyverse, ggplot, and RMySQL. → anything else??
INSTALL → get the packages available in your R environment
From https://cran.r-project.org .
install.packages(package_name)
or using GUI
From GitHub
LOAD → get the package ready for our needs.
See what packages we have in our R environment:
UNINSTALL PACKAGE → remove.packages(package_name)
UNLOAD PACKAGE → detach(NAMA_PACKAGE, unload=true) or using GUI
try to install & load a package:
# Install Package
## Install package from CRAN
# install.packages('dplyr')
## Install package from github
# install.packages('devtools')
# devtools::install_github('hadley/babynames')
## List installed package
# installed.packages()
example
a <- 81
b <- 9
x1 <- a + b
x2 <- a - b
x3 <- b * b
x4 <- a / b
x5 <- b ^ 2
x <- 1:4
y <- 6:9
z <- x+y
example
a <- 81
b <- 9
a == b
[1] FALSE
a <= b
[1] FALSE
a > b
[1] TRUE
a - 72 == b
[1] TRUE
a - 72 > b
[1] FALSE
a - 72 >= b
[1] TRUE
x <- 1:4
x > 2
[1] FALSE FALSE TRUE TRUE
example
a <- 81
b <- 9
a != b
[1] TRUE
!(a == b)
[1] TRUE
(a - 72 == b) | (a - 72 > b)
[1] TRUE
(a - 72 == b) & (a - 72 > b)
[1] FALSE
Mathematical
String
example:
sqrt(16)
[1] 4
str1 = 'Hello'
str2 = 'World!'
# concatenate two strings using paste function
paste(str1,str2)
[1] "Hello World!"
## Assign variable
a <- 10
b <- 8
c <- a + b
d <- a ^ b
i <- sqrt(25)
j <- round(0.34567)
k <- factorial(5)
e <- 'Hello'
f <- 'World'
g <- paste(e, f)
g2 <- paste(e, f, sep=",")
v <- c(1, 2, 3, 4, 5)l1 <- list(1, 2, “a”, “b”)l2 <- list(1, “a”, 3, TRUE, c(5, 6, 7))f <- factor(c("single", "married", "married", "single"));vector
is what is called an array in all other programming languages except R — a collection of cells with a fixed size where all cells hold the same type (integers or characters or reals or whatever).
list
can hold items of different types and the list size can be increased on the fly. List contents can be accessed either by index (like mylist[[1]]) or by name (like mylist$age).
matrix
is a two-dimensional vector (fixed size, all cell types the same).
array
is a vector with one or more dimensions. So, an array with one dimension is (almost) the same as a vector. An array with two dimensions is (almost) the same as a matrix. An array with three or more dimensions is an n-dimensional array.
data frame
is called a table in most languages. Each column holds the same type, and the columns can have header names.
Example vector code:
v = c(1:3) # a vector with [1.0 2.0 3.0]
cat(v, "\n\n")
1 2 3
v = vector(mode="integer", 4) # [0 0 0 0]
cat(v, "\n\n")
0 0 0 0
v = c("a", "b", "x")
cat(v, "\n\n")
a b x
Example list code:
ls = list("a", 2.2)
ls[3] = as.integer(3)
print(ls)
[[1]]
[1] "a"
[[2]]
[1] 2.2
[[3]]
[1] 3
cat(ls[[2]], "\n\n")
2.2
ls = list(name="Smith", age=22)
cat(ls$name, ":", ls$age)
Smith : 22
Example matrix code:
m = matrix(0.0, nrow=2, ncol=3) # 2x3
print(m)
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 0
Example array code:
arr = array(0.0, 3) # [0.0 0.0 0.0]
print(arr)
[1] 0 0 0
arr = array(0.0, c(2,3)) # 2x3 matrix
print(arr)
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 0
arr = array(0.0, c(2,5,4)) # 2x5x4 n-array
# print(arr) # 40 values displayed
Example data frame code:
people = c("Alex", "Barb", "Carl") # col 1
ages = c(19, 29, 39) # col 2
df = data.frame(people, ages) # create
names(df) = c("NAME", "AGE") # headers
print(df)
h <- 1:10
h_mult <- h*5
# get n-th element
h_mult[1]
[1] 5
# subset vector
h_mult[2:4]
[1] 10 15 20
# subsetting with subset()
subset(h_mult, h_mult > 20)
[1] 25 30 35 40 45 50
h <- c(1, 2, 3, 4, 5)
h2 <- c(1:5)
h_mult <- h*5
# get n-th element
h_mult[1]
[1] 5
# subset vector
h_mult[2:4]
[1] 10 15 20
# subsetting with subset()
subset(h_mult, h_mult > 20)
[1] 25
# menggunakan c( )
x <- c(1:10)
x <- c(1,2,3,4,5,6,7,8,9,10)
# menggunakan seq()
x <- seq(1,10,by=1)
# menggabungkan vector dengan rbind() dan cbind()
h <- c(1, 2, 3, 4, 5)
i <- c(2, 5)
rbind(h, i) # by row
Warning: number of columns of result is not a multiple of vector length (arg 2)
[,1] [,2] [,3] [,4] [,5]
h 1 2 3 4 5
i 2 5 2 5 2
cbind(h, i) # by column
Warning: number of rows of result is not a multiple of vector length (arg 2)
h i
[1,] 1 2
[2,] 2 5
[3,] 3 2
[4,] 4 5
[5,] 5 2
x <- c(1:5)
y <- c(6:10)
cbind(x, y)
x y
[1,] 1 6
[2,] 2 7
[3,] 3 8
[4,] 4 9
[5,] 5 10
rbind(x, y)
[,1] [,2] [,3] [,4] [,5]
x 1 2 3 4 5
y 6 7 8 9 10
Mathematical Function
c <- c(1:10)
m <- mean(c)
m
[1] 5.5
Element di dalam-nya bisa berbeda tipe dan ukuran berbeda.
Element bisa tunggal, bisa juga berupa another list.
Dibuat dengan menggunakan fungsi list().
contoh:
```r
varlist <- list(nama="Pandora", jumlahbulan=4, bobotkelas=c(4,3,5,4))
varlist
```
```
$nama
[1] "Pandora"
$jumlahbulan
[1] 4
$bobotkelas
[1] 4 3 5 4
```
Akses isi list:
Menggunakan posisi indeks
Menggunakan operator $ berindex nama untuk mendapatkan element
unlist() → mengubah list menjadi vector
varlist <- list(nama="Pandora", jumlahbulan=4, bobotkelas=c(4,3,5,4))
varlist
$nama
[1] "Pandora"
$jumlahbulan
[1] 4
$bobotkelas
[1] 4 3 5 4
varlist[3]
$bobotkelas
[1] 4 3 5 4
varlist[[3]]
[1] 4 3 5 4
varlist$bobotkelas
[1] 4 3 5 4
# does not have to be the same type
list_a <- list("a", "b", "c")
list_a
[[1]]
[1] "a"
[[2]]
[1] "b"
[[3]]
[1] "c"
list_b <- list(1, 2, 3)
list_b
[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
[1] 3
# ----------------------
list_c <- list(1, "a", TRUE)
list_c
[[1]]
[1] 1
[[2]]
[1] "a"
[[3]]
[1] TRUE
list_c[1]
[[1]]
[1] 1
list_c[[1]]
[1] 1
# ----------------------
list_d <- list(a = "x", b = "y", c = "z")
list_d
$a
[1] "x"
$b
[1] "y"
$c
[1] "z"
list_d["a"]
$a
[1] "x"
list_d[["a"]]
[1] "x"
list_d$a
[1] "x"
# categoric
# levelnya dari urutan alphabet
fact_a <- factor(c("zebra", "beruang", "macan"))
# levelnya ditentukan
fact_b <- factor(c("zebra", "beruang", "macan"), levels = c("macan", "beruang", "zebra"))
fact_a
[1] zebra beruang macan
Levels: beruang macan zebra
fact_b
[1] zebra beruang macan
Levels: macan beruang zebra
# levelnya urutan angka
fact_c <- factor(c(5, 10, 2))
fact_c
[1] 5 10 2
Levels: 2 5 10
factor(c(50, 10, "macan"))
[1] 50 10 macan
Levels: 10 50 macan
matrix_a = matrix(
c(1, 2, 3, 4, 5, 6, 7, 8, 9),
nrow = 3,
ncol = 3,
)
matrix_a
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
matrix_b = matrix(
c(1, 2, 3, 4, 5, 6, 7, 8, 9),
nrow = 3,
ncol = 3,
# By default matrices are in column-wise order
byrow = T
)
matrix_b
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
# Naming rows
rownames(matrix_a) = c("a", "b", "c")
# Naming columns
colnames(matrix_a) = c("d", "e", "f")
matrix_a
d e f
a 1 4 7
b 2 5 8
c 3 6 9
# Naming rows
rownames(matrix_b) = c("a", "b", "c")
# Naming columns
colnames(matrix_b) = c("c", "d", "e")
matrix_b
c d e
a 1 2 3
b 4 5 6
c 7 8 9
# Naming rows
rownames(matrix_b) = c("umur", "jumlah anak", "c")
# Naming columns
colnames(matrix_b) = c("bla", "bli", "blu")
matrix_b
bla bli blu
umur 1 2 3
jumlah anak 4 5 6
c 7 8 9
Struktur dua dimensi seperti table dimana bisa terdiri dari beberapa kolom dan tiap kolom memiliki tipe data yang sama, dan total baris tiap kolom haruslah sama.
terdiri dari beberapa kolom
tipe data yang sama
total baris tiap kolom harus sama
Membuat data frame menggunakan fungsi data.frame
```r
data.transaksi <- data.frame(
kode_transaksi = c(1:5),
nama = c("Ari","Budi","Celine","Darmin","Erik")
)
data.transaksi
```
<div data-pagedtable="false">
<script data-pagedtable-source type="application/json">
{"columns":[{"label":["kode_transaksi"],"name":[1],"type":["int"],"align":["right"]},{"label":["nama"],"name":[2],"type":["chr"],"align":["left"]}],"data":[{"1":"1","2":"Ari"},{"1":"2","2":"Budi"},{"1":"3","2":"Celine"},{"1":"4","2":"Darmin"},{"1":"5","2":"Erik"}],"options":{"columns":{"min":{},"max":[10],"total":[2]},"rows":{"min":[10],"max":[10],"total":[5]},"pages":{}}}
</script>
</div>
Akses isi data frame:
employee <- c('John Doe','Peter Gynn','Jolie Hope')
salary <- c(21000, 23400, 26800)
startdate <- as.Date(c('2010-11-1','2008-3-25','2007-3-14'))
employ.data <- data.frame(employee, salary, startdate)
employ.data
# View(employ.data) # must Capital
data(mtcars)
dim(mtcars)
mtcars[c(3:5), ]
# tidyverse's dataframe
library("tidyverse")
── Attaching core tidyverse packages ───────────────────────────────────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.0 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.1 ✔ tibble 3.2.0
✔ lubridate 1.9.2 ✔ tidyr 1.3.0
✔ purrr 1.0.1 ── Conflicts ─────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
employ.data <- as_tibble(employ.data)
employ.data
a <- 10
b <- c(1, 2, 3, 4, 5)
# data types
class(a)
[1] "numeric"
class(b)
[1] "numeric"
# structure
str(a)
num 10
str(b)
num [1:5] 1 2 3 4 5
# data types
x <- c(1, "a", 3, TRUE)
typeof(x)
[1] "character"
# check if data types -> is.*
is.numeric(10)
[1] TRUE
x <- c(1, 2, 3, 5)
class(x)
[1] "numeric"
typeof(x)
[1] "double"
# Data Type Conversion -> as.*
a = 100
str_a <- as.character(a)
num_a <- as.numeric(str_a)
as.numeric(c("-.1", " 2.7 ", "B"))
Warning: NAs introduced by coercion
[1] -0.1 2.7 NA
Embedded datasets in RStudio:
data() → from RStudio
data(package = .packages(all.available = TRUE)) → from packages installed in RStudio.
Create your own:
vector → c( )
tiga_angka <- c(1, 2, 3)
index start from 1 (not 0)
teks → diapit quote ” ”
teks <- "halo DQLab"dataframe()
read_delim()readxljsonliteRMySQL atau
RMariaDBmongolitegooglesheets4haven atau
foreignEmbedded datasets
# data()
# data(mtcars)
force(mtcars)
Data Frame
## Creating Data Frame
employee <- c('John Doe','Peter Gynn','Jolie Hope')
salary <- c(21000, 23400, 26800)
startdate <- as.Date(c('2010-11-1','2008-3-25','2007-3-14'))
employ.data <- data.frame(employee, salary, startdate)
str(employ.data)
'data.frame': 3 obs. of 3 variables:
$ employee : chr "John Doe" "Peter Gynn" "Jolie Hope"
$ salary : num 21000 23400 26800
$ startdate: Date, format: "2010-11-01" "2008-03-25" "2007-03-14"
Import From CSV
library(readr)
# tidyverse -> read_csv
flavors_of_cacao <- read_csv('data/flavors_of_cacao.csv')
Rows: 1795 Columns: 9── Column specification ─────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (6): Company
(Maker-if known), Specific Bean Origin
or Bar Name, Cocoa
Percent, Company
Location, Be...
dbl (3): REF, Review
Date, Rating
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# base (bawaan R) -> read.csv
flavors_of_cacao <- read.csv('data/flavors_of_cacao.csv')
flavors_of_cacao
Import From Excel
library(readxl)
flavors_of_cacao <- read_xlsx('data/flavors_of_cacao.xlsx')
New names:
flavors_of_cacao
Import From JSON
library(jsonlite)
Warning: package ‘jsonlite’ was built under R version 4.2.3
Attaching package: ‘jsonlite’
The following object is masked from ‘package:purrr’:
flatten
flavors_of_cacao <- fromJSON('data/flavors_of_cacao.json')
flavors_of_cacao
Import From Google Sheets
library(gsheet)
Warning: package ‘gsheet’ was built under R version 4.2.3
mtcars <- gsheet2tbl('docs.google.com/spreadsheets/d/1I9mJsS5QnXF2TNNntTy-HrcdHmIF9wJ8ONYvEJTXSNo')
mtcars
Import From Mongodb
# mongodb+srv://<username>:<password>@cluster0.uqpkp.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
# library(mongolite)
# url <- "mongodb+srv://dqlab:wguifGPUKQZDYX6@cluster0.uqpkp.mongodb.net/dqlab?retryWrites=true&w=majority"
# flavors_of_cacao_4 <- mongo("flavors_of_cacao", url = url)$find()
Import From MySql/MariaDb
# library(RMariaDB)
# con <- dbConnect(
# RMariaDB::MariaDB(), host = "0.0.0.0", port = 3307, username = "user",
# password = "password", dbname = "database")
# res <- dbSendQuery(con, "SELECT * FROM v2021_statement")
# mysql_data <- dbFetch(res)
# dbClearResult(res)
# library(RMySQL)
# con <- dbConnect(
# RMySQL::MySQL(), host = "localhost", port = 3306, username = "root",
# password = "nurimammasri", dbname = "training")
# rs <- dbSendQuery(con, "SELECT * FROM ms_cabang")
# mysql_data <- dbFetch(rs)
# str(mysql_data)
Exercise
# 1. Read dataset from https://github.com/owid/covid-19-data/raw/master/public/data/vaccinations/vaccinations.csv into dataframe
vaccinations <- read_csv('https://github.com/owid/covid-19-data/raw/master/public/data/vaccinations/vaccinations.csv', show_col_types = FALSE)
# 2. read dataset from https://raw.githubusercontent.com/erikaris/dataset/main/indonesia_prov_iso.json
indonesia_prov_iso <- fromJSON('https://raw.githubusercontent.com/erikaris/dataset/main/indonesia_prov_iso.json')
# 3. read iris dataset from https://docs.google.com/spreadsheets/d/1fI9kwibZTpOGPGcTk30TJG740AMyB1KGRsRNrHFUPEw
iris <- gsheet2tbl('https://docs.google.com/spreadsheets/d/1fI9kwibZTpOGPGcTk30TJG740AMyB1KGRsRNrHFUPEw')
# 4. read mysql db from your previous sessions using RMariaDB.
library(RMySQL)
Warning: package ‘RMySQL’ was built under R version 4.2.3Loading required package: DBI
con <- dbConnect(
RMySQL::MySQL(), host = "localhost", port = 3306, username = "root",
password = "nurimammasri", dbname = "training")
rs <- dbSendQuery(con, "SELECT * FROM ms_cabang")
mysql_data <- dbFetch(rs)
str(mysql_data)
'data.frame': 500 obs. of 3 variables:
$ kode_cabang: chr "CABANG-001" "CABANG-002" "CABANG-003" "CABANG-004" ...
$ nama_cabang: chr "PHI Mini Market - Lhokseumawe 01" "PHI Mini Market - Bau-Bau 01" "PHI Mini Market - Bogor 01" "PHI Mini Market - Medan 01" ...
$ kode_kota : chr "KOTA-003" "KOTA-083" "KOTA-039" "KOTA-007" ...
# con <- dbConnect(
# RMariaDB::MariaDB(), host = "127.0.0.1", port = 3306, username = "root", dbname = "minimart")
# res <- dbSendQuery(con, "SELECT * FROM ms_people")
# mysql_data <- dbFetch(res)
look the whole data: type the data name or View()
Look part of the data:
Look at the dimension
Look at the structure:
Tambahan
iris <- read.csv('data/iris_dataset.csv')
iris
# Look the whole data: type the data name or View()
# View(iris)
# . Look part of the data:
head(mtcars)
tail(mtcars)
# . Look at the structure:
library(dplyr)
glimpse(mtcars)
Rows: 32
Columns: 11
$ mpg <dbl> 21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2, 17.8, 16.4, 17.3, 15.2, 10.4, 10.4…
$ cyl <dbl> 6, 6, 4, 6, 8, 6, 8, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 8, 8, 8, 8, 4, 4, 4, 8, 6, 8, 4
$ disp <dbl> 160.0, 160.0, 108.0, 258.0, 360.0, 225.0, 360.0, 146.7, 140.8, 167.6, 167.6, 275.8, 275.8, 275…
$ hp <dbl> 110, 110, 93, 110, 175, 105, 245, 62, 95, 123, 123, 180, 180, 180, 205, 215, 230, 66, 52, 65, …
$ drat <dbl> 3.90, 3.90, 3.85, 3.08, 3.15, 2.76, 3.21, 3.69, 3.92, 3.92, 3.92, 3.07, 3.07, 3.07, 2.93, 3.00…
$ wt <dbl> 2.620, 2.875, 2.320, 3.215, 3.440, 3.460, 3.570, 3.190, 3.150, 3.440, 3.440, 4.070, 3.730, 3.7…
$ qsec <dbl> 16.46, 17.02, 18.61, 19.44, 17.02, 20.22, 15.84, 20.00, 22.90, 18.30, 18.90, 17.40, 17.60, 18.…
$ vs <dbl> 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1
$ am <dbl> 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1
$ gear <dbl> 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 5, 4
$ carb <dbl> 4, 4, 1, 1, 2, 1, 4, 2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2, 1, 1, 2, 2, 4, 2, 1, 2, 2, 4, 6, 8, 2
str(mtcars)
spc_tbl_ [32 × 11] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
$ mpg : num [1:32] 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
$ cyl : num [1:32] 6 6 4 6 8 6 8 4 4 6 ...
$ disp: num [1:32] 160 160 108 258 360 ...
$ hp : num [1:32] 110 110 93 110 175 105 245 62 95 123 ...
$ drat: num [1:32] 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
$ wt : num [1:32] 2.62 2.88 2.32 3.21 3.44 ...
$ qsec: num [1:32] 16.5 17 18.6 19.4 17 ...
$ vs : num [1:32] 0 0 1 1 0 1 0 1 1 1 ...
$ am : num [1:32] 1 1 1 0 0 0 0 0 0 0 ...
$ gear: num [1:32] 4 4 4 3 3 3 3 4 4 4 ...
$ carb: num [1:32] 4 4 1 1 2 1 4 2 2 4 ...
- attr(*, "spec")=
.. cols(
.. mpg = col_double(),
.. cyl = col_double(),
.. disp = col_double(),
.. hp = col_double(),
.. drat = col_double(),
.. wt = col_double(),
.. qsec = col_double(),
.. vs = col_double(),
.. am = col_double(),
.. gear = col_double(),
.. carb = col_double()
.. )
- attr(*, "problems")=<externalptr>
# . Look at the dimension
dim(iris)
[1] 150 5
nrow(iris)
[1] 150
ncol(iris)
[1] 5
length(iris)
[1] 5
class(iris)
[1] "data.frame"
typeof(iris)
[1] "list"
names(iris)
[1] "sepal.length..cm." "sepal.width..cm." "petal.length..cm." "petal.width..cm."
[5] "target"
employee <- c('John Doe','Peter Gynn','Jolie Hope')
salary <- c(21000, 23400, 26800)
startdate <- as.Date(c('2010-11-1','2008-3-25','2007-3-14'))
employ.data <- data.frame(employee, salary, startdate)
table(employ.data)
, , startdate = 2007-03-14
salary
employee 21000 23400 26800
John Doe 0 0 0
Jolie Hope 0 0 1
Peter Gynn 0 0 0
, , startdate = 2008-03-25
salary
employee 21000 23400 26800
John Doe 0 0 0
Jolie Hope 0 0 0
Peter Gynn 0 1 0
, , startdate = 2010-11-01
salary
employee 21000 23400 26800
John Doe 1 0 0
Jolie Hope 0 0 0
Peter Gynn 0 0 0