100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Volledige samenvatting intro to datastructures and algorithms for health $8.56
Add to cart

Summary

Volledige samenvatting intro to datastructures and algorithms for health

 10 views  0 purchase
  • Course
  • Institution
  • Book

This summary includes all lectures and the full book.

Preview 4 out of 64  pages

  • Yes
  • April 22, 2022
  • 64
  • 2021/2022
  • Summary
avatar-seller
INF:
1.project 1: weighted dice:

Computers:
- Let you assemble, manipulate and visualize data sets

A data scientist who knows how to program→ improve the ability to:
- Memorize (store) entire data sets
- Recall data values on demand
- Perform complex calculations with large amounts of data
- Do repetitive tasks without becoming careless or bored

2.1the R user interface:
What can you do:
- Enter: run the code
- Ctrl + C: cancel a command once it has begun (it may also take long to cancel the comman)
What you can type:
- Command: the code you type. It will command your computer to do something for you
- Command line: the line you type the command into
- Colon operator (:) : returns every integer between two integers. It is an easy way to create a sequence of
numbers
- # (known as commenting symbol): R will not run anything that follows a hashtag on a line and allows to add
comments and annotations to the code

Bracketed numbers:
Left: Below you see that [1] appears next to the result → R is then letting you know that this line begins with the first
value in your result.
Right: on the right picture you can see that [14] appears and this means that you start with the 14th value in the
result. Same for the [25] this means that it starts with the 25th number of the sequence.




Incomplete command:
- If you type an incomplete command and press enter, R will type a + for you because it knows something is
missing and therefor it is waiting for you to type the rest of your command

Arithmetic:
- You can use R as a calculator for example to calculate 6/(4-1)

Hashtag (#)
- R will not run anything that follows a hashtag on a line → very useful for adding comments and annotations
to your code

2.2Objects:
What you can type:
- Colon operator (:) : create a group of numbers
- Object: you can save a vector of numbers by using this and this is a name that you can use to call up stored
data
- 1s: you can see which object names you have already used
- t: transpose a matrix
- det: take its determinant

1

,The : operator returns its results as a vector, a one-dimensional set of numbers → So 1:6 results in 1 2 3 4 5 6 and this
is called the vector of numbers

Object:
- A name that you can use to call up stored data
- So for example you can save data into an object like a (as you can see in the picture) and wherever R
encounters the object a, it will replace it with the data saved inside
- You can name an object in R almost anything you want, but there are rules:
o Cannot start with a number
o Cannot use some special symbols like
- Watch out when making an object with the capitalization; name is something different for R than Name
- R will overwrite any previous information stored in an object without asking you for permission → do not use
names that are already taken
- R will replace an object with its content (what is stored in the environment pane) with its contents whenever
the object’s name appears in a command.




SO:
1. To create an R object, choose a name and then use the less-than symbol (<) , followed by a minus sign (-), to
save data into it. R will make an object, give it your name, and store it in whatever follows the arrow.
a. A <- stores 1 in an object named A
2. When you ask R what’s in A, R tells you on the next line
3. You can use your object in new R commands, too. Since A previously stored the value of 1, you are now
adding 1 to 2.

Environment pane:
- This pane will show you all of the objects you have created since opening R studio
- This is the right upper pane

1s:
- By using this function you can see which object names you have already used.


You can do all sorts of math with the die (1:6) and when typing die R will replace an object with its contents:
- Math isn’t so helpful for rolling dice, but manipulating sets of numbers will be your stock and trade as a data
scientist.

→ so you do 1 2 3 4 5 6 and all -1 so you get 1-1=0 and 2-1=1 etc.
→ so you do 1 2 3 4 5 6 and all /2 so you get 1/2=0,5 and 2/2=1 etc.

→ so you do 1 2 3 4 5 6 and all times die so 1*1 = 1 and 4*4=16 etc. → use two or more vectors
SO: Element wise-execution:
- When you manipulate a set of numbers, R will apply the same operation to each element in the set → R
doesn’t always follow the rules of matrix multiplication
- This means that when you run die-1, R subtracts 1 from each element of die! ( this is the same thing as you
can see above in the example)
Use two or more vectors:
- For example when you run die*die , R lines up the two die vectors and then multiplies the first element of
vector 1 by the first element of vector 2. R then multiplies the second element of vector one with the second
element of vector 2 etc.

2

, → When R performs element-wise execution, it matches up vectors and then manipulates each pair of elements independently.


Vector recycling: If you give R two vectors of unequal lengths, R will repeat the shorter vector until it is as long as
the longer vector.
- This isn’t permanent → shorter vector will be its original size after R does the math.
- It helps R do element-wise operations. These operations are a very useful feature in R because they
manipulate groups of values in an orderly way. They will ensure that values from one observation or case are
only paired with values from the same observation or case.




R can also do traditional matrix multiplication:
- You have to ask R to do this
- You can do inner multiplication with the %*% operator and outer multiplication with the %o%




2.3functions: are needed to roll the die → you’ll need to randomly select one of the die’s
values. And for that you will need a function
What you can type:
- Round: round a number
- Factorial: you can calculate its factorial
- Sample: this takes two arguments; a vector named x and a number named size
- Args(name of the function): look up the function’s arguments
- Replace=TRUE; causes the sample to sample with replacement, instead of without → sample may select the
same value on the second draw.
- Sum: add up the numbers

How to use a function:
- Just write the name of the function and then the data you want the function to operate on in parentheses




3

, Argument:
- The data that you pass into the function
- The argument can be:
o Raw data
o An R object
o The results of another R function
▪ In this case R will work from the innermost function to the outermost (as you can see in the
picture)
→ you can see that R first looks up die, then calculates the
mean of one through six and then rounds the mean→ this
means that when you links together, R will resolve them from
the innermost operation to the outermost




How to roll the die;
- With R’s sample function. Sample takes two arguments: a vector named x and a number named size. Sample
will return size elements from the vector



- To roll the die and get a number back: set x to die and sample one element from it → you then get a new
(maybe different) number each time you roll it




can also be written as → (every argument in every R function has a name. You
can specify which data should be assigned to which argument by setting a name equal to the data, as in the preceding
code. This becomes important as you begin to pass multiple arguments to the same function; names help you avoid
passing the wrong data to the wrong argument. You notice that r users do not often use the name of the first argument
in a function.

How do you know which argument names to use?
- Use a name that a function does not expect → ERROR

o
- Look up function’s arguments with args
o You place the name of the function in the parentheses () behind args


o → round function takes two arguments, one named X and one named digits

default value:
- The digits argument of round is already set to 0 → R function will take optional arguments like digits. These
arguments are considered optional because they come with a default value. You can pass a new value to an
optional argument if you want, and R will use the default value if you do not
To override the default, you can supply your own value for digits (upper is with the
default value and lower with overridden default) →


Write out the names of each argument after the first one or two when you call a function with multiple arguments
because:
- It helps you and others understand you code
- Obvious which argument your first input refers to (sometimes second input as well), but need a large memory
to remember the third and fourth arguments of every R function
4

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller valeriedinjens1. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $8.56. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

53068 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$8.56
  • (0)
Add to cart
Added