0% found this document useful (0 votes)
16 views13 pages

Week14 Asynch

Uploaded by

Monica Simon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views13 pages

Week14 Asynch

Uploaded by

Monica Simon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Working with

data

ASYNCHRONOUS

This Photo by Unknown author is licensed under CC BY-SA-NC.


Review from Vectors, matrices
Functions
week 13 and data frames

Setting a working Datasets APIs and Spatial


directory & Loading data Data
History & ethos of R as free and opensource

Interpreted language

Let's review
Extensible object system

Writing comments
Creating basic objects
Working with R- Getting help
Saving
Create objects
and call them
String <- "hello world"

Math <- 24*2

String

Math
More about vectors
A vector is a series of values. It contains elements of the
same type.

If consecutive numbers
(like 1, 2, 3, 4, 5, 6) use consecutive<- 1:6
a colon:

Often created using the c() vector <- c(1,54,31,20)


function:
interests<-c("kitties",
C is for "unicorns", "coffee",
combine "internet", "avocados")
The c() will numbers<-c(2, 4, 48, 1,
coerce 5, 7, 1650)
elements of
the same
type into a x <- c(1, 5.4, TRUE,
vector "hello") #will all be
forced into charactor
Matrices Data Frames
Homogeneous data arranged in 2-dimensional Heterogeneous data table (like excel)
rectangular organization Can contain multiple data types
M*n arrays Multiple columns (called fields)
Restricted to similar data types Basically a list of vectors of equal length
Use them to perform arithmetic

matrix = matrix (c(1, 2, 33, 4, 5, beasts <- c('unicorn','cyclops','bigfoot')


6), nrow = 2, ncol = 3, byrow = 1) price <- c(21000, 23400, 26800)
date <- as.Date(c('2020-11-1','2018-3-25','2017-3-
14'))

Beasts_df <- data.frame(beasts, price, date)


Take inputs Inputs can be an object (e.g.
(called arguments) and return some data) OR they can specify
outputs. options

Functions
You can either manually specify a function’s arguments or
(also called use the function’s default values.

commands)
perform Generally take the form: function_name(arguments)

tasks in R
Each package has their own set of functions
R saves data to your working folder

R sets a relative file path in your code

Setting a
working check the working directory: getwd()

directory
Set the working directory in Rstudio's GUI

Or you can set it with a setwd("/Users/monica/Dropbox/r")


function("path")
There are several
datasets built
into R
Learn about them by typing in the
console:

help(package="datasets")
CSV APIs
Name <- read.csv("Path where your
CSV file is located on your
computer\\File Name.csv")

Loading external data


APIs =Application Programming Interfaces

Set of rules that allow one software application to


interact with another

What is an
API? A ‘request’ follows certain programmatic rules. It is
submitted to a server and the server returns a
‘response’ containing content in an expected format

There are many types of API

You might also like