GEOG 264- Midterm #2

49 flashcardsby Alyssa
Study these flashcardsFree · spaced repetition · iPhone, Android, Mac & web

All cards

1
plots- basic
plot(x,y)

main= title
xlab/ylab= axis titles
col= colour
pch= shape of point
ces.main= size of title
cex.axis= size of tic marks
cex.lab= size of axis titles
xlim and ylim
2
add lines to plots
horizontal:
abline(h= n, col= , lty= type, lwd= )

vertical:
abline( v= , )

sloped:
abline(a= , b= )
3
add points to plot
points (x, y, parameters)
x and y can be vectors to get multiple points

use to get 2 plots on one graph
4
add text inside a plot
text(x, y, labels= )
5
line plot
add parameter
type= "l" or "line"
lty= "dashed"
6
legend
( "position", legend= c(names), pch= , col= c(colours), cex= size of box/ words)
7
barplots
variable of plot <- c(list of data)
barplot( variable of plot, col= , main= , ylab= , names.arg= c(names) )
8
histogram and pie chart
hist ( data , paramters, xlab= )
ylab set automatically to frequency

variable of chart <- c(list of data)
pie( variable of chart, parameters)
9
convert a matrix to a vector
qctemp <- read.csv("QuebecTemp.csv")
linear <- rep(0, nrow(qctemp)*ncol(qctemp))
counter <- 1

for(row in 1:nrow(qctemp)) {
for(col in 1:ncol(qctemp)) {
linear[counter] <- qctemp[row,col]
counter <- counter + 1
}
}
linear
10
convert a vector to matrix
numrows <- length(linear) / 13
numcols <- 13
qctemp2 <- matrix(0, nrow=numrows, ncol=numcols)
counter <- 1

for(row in 1:numrows) {
for(col in 1:numcols) {
qctemp2[row, col] <- linear[counter]
counter <- counter + 1
}
}
11
diag()
ex: diag(5)
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
12
matrix multiplication
A %*% B
13
matrix inversion
solve(A)
14
length(text)
counts how many strings there are
15
backslash as escape character
cat("Please enter \"C\" if you wish to continue")
# Please enter "C" if you wish to continue

cat("C:\\ProgramFiles")
# C:\ProgramFiles

cat("Hello\nWorld") # splits words into 2 lines
# Hello
# World

cat("\tHello") # extra space at start
# Hello

cat("Hello World") # no space
# HelloWorld

only works with cat not paste
16
logical operations on strings
compares the character in the same position in the string
"snow" > "sleet" # TRUE because 'n' comes later than 'l' in alphabet
"snoW" < "snow" # FALSE because capital letters are worth more
17
substring
substr(text, 1st character, last character)
18
NaN
not a number
ex:
0/0
Inf + -Inf
Inf/Inf
19
adding to a vector
vector <- append(vector, new_elem)
20
difference between lists and dataframes vs vectors and matrices
lists and data frames can store multiple data types while vectors and matrices can only store single data types
21
subset a list
list [[element]] [which element of element]
22
create data frame manually
name <- data.frame (
col1= c(variables)
col2= c(variables)
)

need c() even with one element
23
base package
automatically installed and loaded in standard R
24
recommended
come with standard R install-
although they are install you need to load them to use
25
contributed
by users can get it through CRAN
not included with install of R because there are too many
need to install and load these packages
26
install packages
install.packages("name")
27
function
name <- function (parameter) {
code
return (result)
}
name ( )
28
separate the name to "last name, first name"- function example
lastname <- function(name) {
for(i in nchar(name):1) {
if (substr(name, i, i) == "") {
location <- i
break
}
}
return(paste(substr(name, location + 1, nchar(name)), ", ",
substr(name, 1, location -1, sep= "")))
}

lastname("Marie Ganon")
29
typeof
is more specific than class ( )
30
add names to a list
names(list) <- c( "names")
31
attributes
for list: names
for data frame:
32
delete element from a list
list [["names of element"]] <- NULL
33
using lists to return multiple items
multi_return <- function() {
my_list <- list("color"="red", "size"= 20, "shape"= "round")
return(my_list)
}
a <- multi_return
34
coersion
converting from one data type or data structure type to another
ex: adding logicals as if they are numbers
35
Properties of version control systems
Changes are saved sequentially
Different versions can be saved
Multiple versions can be merged

Some word processors let us deal with this a little better:
Microsoft Word’s Track Changes
Google Docs’ version history
LibreOffice’s Recording and Displaying Changes
36
version control system
A version control system is a tool that keeps track of
changes, and creates different versions of files:
Each record of changes is a commit
Each commit contains metadata
Commits and their metadata make up a repository
Version control is like an unlimited "undo"
Version control also allows many people to work in
parallel
37
Reproducibility and Replicability in GIScience
"reproducible": same data and methods
"replicable": different data and software
38
Replication Crisis" in GIScience?
Many established geoservices lack full documentation
Geospatial datasets can be large and computationally
intensive
Proprietary software offers "point and click" user
experience
Maps ≠ a full representation of research results
39
Approaches to Replicable GIScience
Containerization: a package of software and data that
can be re-used and archived across platforms

Research compendium: a container of research
methods (i.e., docs, code, data, ...) and a means of
sharing the collection
40
creating a repository:

We use git init to initialize a repository, and git
status to check project status:

We can tell Git to track a file using git add
... and record changes using git commit
git commit -m "text"
41
directories in git
Git does not track directories on their own, only files
within them.
If you create a directory in your Git repository and
populate it with files, you can add all files in the
directory at once by: git add <directory-with-files>
42
key points of git
- git init initializes a repository.
-Git stores all of its repository data in the .git
directory.
-git status shows the status of a repository.
-Files can be stored in a project’s working directory
(which users see), the staging area (where the next
commit is being built up) and the local repository
(where commits are permanently recorded).
-git add puts files in the staging area.
- git commit saves the staged content as a new
commit in the local repository.
- Properties of a good commit message: short,
descriptive, and imperative
43
key point once on git hub
A local Git repository can be connected to one or more
remote repositories
Use the HTTPS protocol to connect to remote
repositories
git push copies changes from a local repository to a
remote repository
git pull copies changes from a remote repository to
a local repository
44
collaboration
Use git clone to download a copy of the owner's
repository for the first time: git clone link

git clone copies a remote repository to a local
repository with origin automatically set up
When conflicts are detected, the version control system
highlights conflicts so they can be resolved manually
45
local variables
local varibales are declared within functions such as i or location
they are only known to the functions. Variables can be local to nested
functions and are invisible to the outer function.

This is also the same even if names of local and global varibales match
46
global varibales
varibales outside of functions are called global. They exist throughout the execution of a program
47
tracing with inner fucntions
outer_func <- function() {
print(a)
a <- 20
inner_func <- function() {
a <- 30
print(a)
}
inner_func()
print(a)
}
a <- 10
outer_func()
# 10
# 30
# 20
48
combine function calls
kelvin_to_celsius(fah_to_kelvin(32))
49
nest subfunctions
fah_to_cel <- function (temp_F) {
fah_to_kelvin <- function(temp_F) {
temp_K <- ((temp_F- 32) * (5/9)) + 273.15
return(temp_K)
}
kelvin_to_celsius <- function(temp_K) {
temp_C <- temp_K - 273.15
return(temp_C)
}
temp_K <- fah_to_kelvin(temp_F)
temp_C <- kelvin_to_celsius(temp_K)
return(temp_C)
}
fah_to_cel(40)
Study all 49 cards for free