I. Ozkan, PhD 
 Professor 
 MIS 
 Cankaya
University
 
iozkan@cankaya.edu.tr
  
Fall 2025
✅ Why Programming
✅ Why
✅ RStudio IDE
❌ Basic
❌ Data Types in
Every task [and possibly project] can be handled
If you know how to handle the program then both possible
Project is a bit easier way
In this course manual creation is recommended to let you learn the structure
Create a directory structure for this course such as
MIS207/ 📂
data/ 📁
*.csv *.txt, *.xlsx
,
images/ 📂
.jpg, *.png, *.bmp, *.svg
code/ 📁
calculater.r, calendar.r,
test.r
HW/ 📁
HWTemplate.rmd, firstHW.rmd,
importEx.rmdAll addresses are relative (we will see examples)
For More Details please visit RStudio User
Guide, Project section https://docs.posit.co/ide/user/ide/guide/code/projects.html
Default R prompt is >
Can be changed with options() function
options(prompt="R> ")  
options(prompt="> ")  
“+” is continuation for incomplete line
library(tidyverse)
dat <- tibble(names = c("smile","school","office","blush","smirk","heart_eyes"),
              emoji = map_chr(names, emo::ji)) %>% 
  tibble::rowid_to_column("n")
All of the text, values, assignments etc. will be interpreted as comment after # symbol
x = 3#5
x
x = #35
# x = 35
nothing happens
Recommended
x <- 3  
or (?)
x = 3  
<- 
or  =## [1] 3
## [1] 5
## [1] 7
x   
X  
Legal R Names: Variable (object) names can be combinations of letters, numbers, periods (.) and underscores (_)
We will discuss naming in programming style guide section
R has several built in Constants, Functions,.., objects in general
For example c, T, F, t, pi
Avoid any assignment to built in objects
## [1] TRUE
## [1] FALSE
## [1] 3.141593
## [1] 2.718282
## [1] 8
## [1] 13
What happens here?
## [1] FALSE
+, -,
*, /, ^, %%
(modulo), %/% (integer division)## [1] 2
## [1] 20
## [1] 10
## [1] 2
## [1] 8
## [1] 2
## [1] 2
## [1] 2
## [1] 3
Scientific Notation: e
## [1] 1000
## [1] 210
From highest to lowest
+ Parentheses: (, )
+ Exponents: ^ or **
+ Multiply: *
+ Divide: /
+ Add: +
+ Subtract: -
## [1] 30
## [1] -180
## [1] 2
## [1] 2
## [1] 1000
## [1] 2
## [1] 2
## [1] 24
## [1] 24
## [1] 24
## [1] 4e-05
## [1] 12000
## [1] Inf
## [1] -Inf
## [1] NaN
Logical operators are operators that return
TRUE and FALSE
values
| Comparisons | |
| Operator | Description | 
|---|---|
| < | less than | 
| <= | less than or equal to | 
| > | greater than | 
| >= | greater than or equal to | 
| == | exactly equal to | 
| != | not equal to | 
| Results: Are Logical, TRUE and FALSE | |
## [1] TRUE
## [1] FALSE
## [1] TRUE
## [1] TRUE
## [1] TRUE
## [1] TRUE
## [1] TRUE
## [1] TRUE
## [1] TRUE
## [1] FALSE
## [1] FALSE
## [1] TRUE
## [1] TRUE
| Logical Operators | |
| Operator | Description | 
|---|---|
| !x | logical negation, (NOT) | 
| x & y | elementwise logical AND | 
| x && y | logical AND (left to right) | 
| x | y | elementwise logical OR | 
| x || y | logical OR (left to right) | 
| xor(x,y) | elementwise exclusive OR | 
| isTRUE(x) | as name suggested | 
| isFALSE(x) | as name suggested | 
| &&, ||: appropriate for programming control-flow | |
TRUE + TRUE # = ? 
TRUE + FALSE # = ?
TRUE - TRUE # = ?
!TRUE # = ?
!FALSE # = ?
TRUE & FALSE # = ?  
TRUE | FALSE # = ? 
TRUE * FALSE # = ? 
TRUE == TRUE # = ? 
TRUE == 1 # = ? 
TRUE == 0 # = ? 
TRUE == -1 # = ?
FALSE == 0 # = ? 
FALSE == -1 # = ?
FALSE == 0.5 # = ?
## [1] 2
## [1] 1
## [1] 0
## [1] FALSE
## [1] TRUE
## [1] FALSE
## [1] TRUE
## [1] 0
## [1] TRUE
## [1] TRUE
## [1] FALSE
## [1] FALSE
## [1] TRUE
## [1] FALSE
## [1] FALSE
trigonometric functions
## [1] 0.841471
## [1] 1.224606e-16
## [1] 1
## [1] 0.5403023
## [1] -1
## [1] 6.123032e-17
## [1] 1.557408
## [1] -1.224647e-16
## [1] 1.633124e+16
## [1] 0.7853982
## [1] 1
## [1] TRUE
## [1] 2
Logarithms and Exponential
## [1] 0
## [1] 1
## [1] 1
## [1] -1
## [1] 5
## [1] -5
## [1] NaN
## [1] NaN
## [1] NaN
## [1] -Inf
## [1] 0
## [1] 1
## [1] 2.718282
## [1] 2.319777
Computers may represent decimal numbers with a certain degree of precision. Two numbers which look the same when printed out by R, may actually have different underlying representations and therefore be different by a small margin of error (called Machine numeric tolerance). If numbers are not integers, use
all.equalfunction
## [1] 3.141593
## [1] "Mean relative difference: 1.102658e-07"
## [1] TRUE
## [1] "Mean relative difference: 0.0004051864"
Note: Recall <- or
-> are assignment operators 
## [1] 0.1
## [1] 0.2
## [1] FALSE
## [1] "Mean relative difference: 1"
## [1] "numeric"
## [1] "double"
## [1] 0.3
## [1] 0.02
## [1] 0.5
## [1] 0.6309573
## [1] 10
## [1] 100
## [1] 5
##  [1] "Description" "l"           "l_table_1"   "l_table_2"   "lstr"       
##  [6] "lstr2"       "lstr3"       "Operator"    "x"           "y"          
## [11] "z"
##  [1] ".Random.seed" "Description"  "l"            "l_table_1"    "l_table_2"   
##  [6] "lstr"         "lstr2"        "lstr3"        "Operator"     "x"           
## [11] "y"            "z"
## function (name, pos = -1L, envir = as.environment(pos), all.names = FALSE, 
##     pattern, sorted = TRUE) 
## {
##     if (!missing(name)) {
##         pos <- tryCatch(name, error = function(e) e)
##         if (inherits(pos, "error")) {
##             name <- substitute(name)
##             if (!is.character(name)) 
##                 name <- deparse(name)
##             warning(gettextf("%s converted to character string", 
##                 sQuote(name)), domain = NA)
##             pos <- name
##         }
##     }
##     all.names <- .Internal(ls(envir, all.names, sorted))
##     if (!missing(pattern)) {
##         if ((ll <- length(grep("[", pattern, fixed = TRUE))) && 
##             ll != length(grep("]", pattern, fixed = TRUE))) {
##             if (pattern == "[") {
##                 pattern <- "\\["
##                 warning("replaced regular expression pattern '[' by  '\\\\['")
##             }
##             else if (length(grep("[^\\\\]\\[<-", pattern))) {
##                 pattern <- sub("\\[<-", "\\\\\\[<-", pattern)
##                 warning("replaced '[<-' by '\\\\[<-' in regular expression pattern")
##             }
##         }
##         grep(pattern, all.names, value = TRUE)
##     }
##     else all.names
## }
## <bytecode: 0x000001972cc9fdc8>
## <environment: namespace:base>
Some/Many/All of these can be downloaded and installed on the local library folder
.libpaths(): gets/sets the library trees within
which packages are looked for
## [1] "C:/Users/CANKAYA/AppData/Local/R/win-library/4.5"
## [2] "C:/Program Files/R/R-4.5.1/library"
## [1] "C:/PROGRA~1/R/R-45~1.1/library"
Some important functions for package installation and call:
install.packages(),
devtools::install_github() - later, library(),
require() (designed to use in a function) install.packages(pkgs, lib, repos = getOption("repos"),
                 contriburl = contrib.url(repos, type),
                 method, available = NULL, destdir = NULL,
                 dependencies = NA, type = getOption("pkgType"),
                 configure.args = getOption("configure.args"),
                 configure.vars = getOption("configure.vars"),
                 clean = FALSE, Ncpus = getOption("Ncpus", 1L),
                 verbose = getOption("verbose"),
                 libs_only = FALSE, INSTALL_opts, quiet = FALSE,
                 keep_outputs = FALSE, ...)
                 
install.packages("ggplot2") and
install.packages(pkgs="ggplot2") are both valid usage.
install.packages("ggplot2") states that the first argument
is "ggplot2"
Arguments match either by names, i.e.,
install.packages(pkgs="ggplot2") or by positions
install.packages("ggplot2")
To use a function from a package, first of all package should be
loaded and attached using either library(ggplot2) or
require(ggplot2)
library() or require() functions, from the
search path, detach() function can be useddetach(name, pos = 2L, unload = FALSE, character.only = FALSE,
       force = FALSE)
Some packages that are necessary for this course are collected in
the name of tidyverse
Do visit tidyverse web site https://www.tidyverse.org/
install.packages("tidyverse")?<function name> open help page
Example: ?lm: for lm() function
lm {stats}  R Documentation
Fitting Linear Models
Description
lm is used to fit linear models, including multivariate ones. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance (although aov may provide a more convenient interface for these).
Usage
lm(formula, data, subset, weights, na.action,
   method = "qr", model = TRUE, x = FALSE, y = FALSE, qr = TRUE,
   singular.ok = TRUE, contrasts = NULL, offset, ...)
For operators ?"<operator>"
Example: ?“*” for multiplication
Arithmetic {base}   R Documentation
Arithmetic Operators
Description
These unary and binary operators perform arithmetic on numeric or complex vectors (or objects which can be coerced to them).
Usage
+ x
- x
x + y
x - y
x * y
x / y
x ^ y
x %% y
x %/% y
Arguments
??<function name> is help from all
packages
Example: ??left_join
Example:
help("anytime", try.all.packages = TRUE)
From a specific package:
help("anytime", package = anytime)
help(package=anytime) (if anytime package is
installed)Books: Try to visit available books online
Manuals/Documents
Contributed Documents on website
Visit R-Project, website
Click Contributed
Visit R-Journal website and browse articles, R-Journal
Visit Journal of Statistical Software website and browse articles, Journal of Statistical Software
…
Community Websites/Blogs/etc
Visit Posit (R-Studio) Community Website, Posit, R-Studio Community
Visit stackoverflow website stackoverflow
for Lecture Notes, short documents etc., for more…