 the recording. We still have a lot of slides to do so let's just continue with the slideshow and hoping that you learn a little bit more about R. So one of the things that I like about R is that help is available. If you don't know what you want to do, well if you know what you want to do and you want to just see the help file for a certain function like for example I want to see the help file of the standard deviation function which is the SD function you can just do question mark SD. If you want to search for something you can do question mark question mark and then the term that you want to search for so if you want to know like something about proteins right the normal lecture 5 is about proteins and you want to know are there any functions in R which deal with proteins you can do question mark question mark proteins and then it will show you all of the help files that have the word protein somewhere in them. So as an example you can do question mark sec and open the help file for the sequence function and you can even ask for the help file of the add function so the plus function but the plus function you have to use quotes because of course question mark plus it doesn't understand that so you have to add the double quotes and you can also search for things like obesity or other things so there's a lot of help in R. The help files are a little bit archaic if you see them for the first time but the thing is you should scroll all the way down and then there's an example. Every help file in R is required to have an example at the bottom so scrolling all the way down it shows you just a little bit of an example on how to use this function and you can copy paste the example into R and see what it does exactly. Alright so let's talk about the types of data in R so in R we have logical values so logical values are the Boolean values either being true or false there is no other logical value well NA in theory not missing could be a logical value as well but logical values in R are defined as being true or false we have numeric values which are for example 5 or 7.9 or 100.6 R doesn't make a distinction between an integer so a whole number and a floating point number like 7.9 in R everything is called a numeric so numeric values are everything which are a number so for example infinite is a numerical value both in the sense of infinite as an integer as infinite as a floating point. Characters are also available those are called strings in different languages so if you're doing Java then it's called a string and in C it's a gar pointer so a gar with a star there but in R it's called a character and the character is for example 1 2 3 when you place it between code quotes it automatically becomes a character in R we have a vector type so a vector type is something which is multiple things in kind of a little list so it's in mathematics this would be an array in many other languages it's also an array or a list but in R it's called a vector because R is a mathematical language it tries to stay close to the mathematical names so vectors come in three different types so a vector can contain numerical values it can contain character values or it can contain logical values and it will always refer to the highest one so if I for example put the one into this vector then this will be a character vector because of course the character string one cannot be represented by a numerical value so all of the other numerical values within the vector will become character values and this is why the R type system is so difficult because it will always go to more or less the type which can contain everything so the order is logical is the lowest type numeric is the middle type and character is then the highest type so if you put a numeric value into a logical vector the logical values will be turned into a numerical value and because the numerical value has precedence above the logical values and of course you can make matrices so matrices are two-dimensional arrays more or less like an Excel table the restriction in R is that a matrix is again bound to be any of these three types so a matrix can only contain numeric values it can contain character values or it can contain logical values so you can't have a matrix which for example has a column with character values and then in the next column a numerical values then that whole matrix will be turned into a character matrix because of the fact that character is you can represent numeric values using characters but you can't represent characters using numerical values so a little bit more difficult so when you're dealing with types it's it's often useful so especially if you're dealing with vectors then something is which is very which you can use a lot is the length so length will give you the length of the vector right so if we have a vector like v 1 here which contains 1 2 3 4 5 6 elements then the length of v 1 so if I ask for the length of variable v 1 it will tell you that 6 SDR will show you the structure of an object which is really useful if you have a list and in inside of these lists there are different things so SDR can help you figure out what the structure is of an object when it is a multi multi-level list we will get to lists the class will tell you which class or type an object has so in this case numeric logical or character and names allow you to set names on a vector but it will also allow you to get the names so you can assign into the names function using the arrow to set the names of an other of a vector you can force things to be of a certain type by using as and then for example as dot logical or as dot numeric to force things to become numeric of course when you force things there is a chance that stuff will become NAN so not a number or that it will become NA for missing you can ask if something is of a certain type so there's three functions is logical is numeric and is character that allow you to test if a certain object contains numeric values character values or logical values so when you want to create a vector or matrix you can do this by by well a vector you can create in in three ways so you can use the C function to create a vector which just says which we used before like C one two five point three six minus two and four so this will C stands for combine these will combine these loose elements into one vector besides that you can also use sec sec is of course very handy when you want to create sequences of numerical values or sequences of characters so you say from to and by so you can for example make a sequence from one to a hundred by five this means that it will step five every time so then you get a you get a vector which contains one six eleven sixteen twenty one and so forth so that this will this will just skip numbers in the middle you can also make a vector by using the rep function so the rep function just repeats the object that you put in there and x amount of times so that's the second parameter is times so how many times do you want to have it repeated for matrix we can make a matrix by using the matrix function so you say matrix then you give it a vector of numbers which you want to put into the matrix and then you tell it I want to have so many rows and so many columns of course the vector has to contain number of rows times number of column of elements right so like I did here when I made my matrix I make five rows four columns and I put the numbers one to twenty in there and of course one to twenty the length of one to twenty is five times four the double point here is is a little bit cheating well it's one of these operators in our and this also allows you to define a vector right one double point twenty means one to twenty so it's just the numbers one two three four five six seven eight nine ten up until twenty and the double point is kind of the sequence function when the buy is one so the double point operator is a sequence from to and then the buy is always one you can see bind if you want to create a matrix imagine that I have two vectors which both have a length of five then it can say see bind vector one vector two and then I will get a matrix which has two columns each and five rows I can use our bind which will bind stuff together in a row wise fashion so you can see bind that that just means you you add new columns to an already existing matrix or you make a new matrix based on vectors by using the columns of binding them column wise and our bind this does the same thing but this does it on a row by row basis so if I have two vectors each containing five objects then our bind will give me two rows and five columns while C bind will give me two columns with five rows hope that's clear all right like I said there's this this additional one to create vector so I can make something called V1 containing the numbers one two four I can make V2 which is a sequence from one to a hundred by seven I can make for example V3 by repeating the number one four times so this is how it looks like and then I can make V2 which repeats the number A four times so this makes a character vector a numeric vector a numeric vector another numeric vector the matrix is more or less the same thing so I can do why one is a matrix of one to twenty number of rows is five the number of columns is four here I'm doing something which is which I changed the slide so I'm sorry that I changed the slide because here I'm binding V1 V2 but that should actually be V1 V3 so I didn't because I added this example of the sequence function to it and then I forgot to update the number here so here I'm making a matrix which is a matrix which has four rows because V1 has four elements V3 has four elements so hey I can do this and I can do why three which is a row bind so this will create a four by two matrix and the row bind here will create a two by four matrix and of course if I want to have more control I can just use the matrix function and then specify how many rows and how many columns I want all right so if you then type the name of the vector right so if I have a vector and I type the name of the vector then shown in R it will show you when you type a vector it will show you like this so it will do this square bracket with one inside and then it will show you the first elements of the vector and then of course it will continue on the next row but then it will have a square bracket with the next index so the first index in this vector is a value which is missing and a when you have a matrix and you type in you type the name of the matrix or the name of the variable containing the matrix then R will print it like this so it will put the rows here and it will put the columns here and you see that it uses comma one and that means this is the whole column one it will use one comma and then this is the whole row so this goes to buy the indexes so there's indexes here on the vector there's indexes on the matrix if you want to index stuff from a vector then we can use the square brackets like we already saw so if this is my vector called V containing a b c d e f g and I then if I want to get the fifth element out I do v 5 and then I get the e out because this is the 1 2 3 4 5th element if I want to get the second to the fifth element out so if I want to make a subset of the vector V then I can do 2 to 5 right and it will get 2 to 5 out if I want to have a sequence which if I want to get like parts of the vector out which are not attached to each other then I can use the c function to make a new vector so you can use a vector a numeric vector to index another vector which I'm doing here so I'm making a vector which is 2 to 5 so 2 3 4 and 5 and then I'm adding 8 to that vector and then using that to select from V I hope that's clear like this is generally where things become a little bit iffy and people start like oh but this is it's not difficult but it's like if you want to figure this out by yourself then it's it's it's difficult like the indexing in vectors is already hard but this will of course get the same as before sir element 2 to 5 but it will also get the h element so you get a vector back which has a length of 5 which contains B C D E and H so it's just creating a vector and this vector can be used as the index to another vector hope that's clear the same thing goes for a matrix so a matrix can be indexed in more or less the same way so here we have four selections from a matrix and I've colored what will be selected so I can do M 1 2 3 of 1 so this means give me the first three rows of the first column which is this little piece here I can also say give me from the fifth row the third to the sixth column which will select these values here I can select singular values as well so using M 8 comma 7 so of course M here is the is the name or the variable name of the matrix so 8 7 is this element here so the a throw 7 column and if I want to get a whole column I can just say M square bracket open do a space or don't because the space is not needed but you say comma 9 and this will give you the entire 9 factor of the matrix and of course you can get the whole first row by just doing M square bracket open 1 comma nothing square bracket close then you will get the whole first row of the matrix alright and of course here you can use the same structure so you can also use the C function to for example select 3 to 6 comma 8 and then it will take the 8th number out as well alright so again types of data we have logicals true and false we have numerical values which are 5 7.9 and then 100.6 we have character values we have vectors and we have matrices and to make it a little bit more versatile right because a vector and a matrix can only contain a single type like either numeric character or logical of course sometimes you want to have a matrix which in which different columns have different elements or you want to create a vector in which each element of the vector is of a different type so R provides you two other data structures called the data frame and it contains the list so a data frame you can is a matrix which can contain multiple basic types and it can only contain multiple basic types in each of the columns so each column can be a different type so imagine that I have v1 being 1 2 3 and 4 which is in so v1 is a numeric vector v2 is a character vector and v3 is a logical vector then I can say d is a data frame where I take v1 v2 and v3 and what it now will do it is well it will create a matrix a more or less a data frame right because it's its own type the first column will be numeric and contain v1 the second column will be character and will contain v2 and the third column will contain a logical data type which is v3 lists are even more more of a difficult thing to grasp because if you make a list you can put anything in every element of the list so you can even put a matrix in a list you can put a list in a list so this allows you to do like multi-dimensional like lists and all of these things but lists are very versatile lists allow you to give things names in one go so I can make a list for example which is the first element has something called name equals Fred then the second element is actually numbers equals v1 right so I just put into this second element of the list a vector which contains four elements and then I at the third point in the list I create something which is age and this has the value 5.3 so here you can see the versatility I can put the whole list or the whole vector here into the list I could even put the whole data frame in so I could say numbers equals D or I could say data frame equals D and it will just at the second position put the whole made a whole data frame into this list alright there's another type in R which is called the fucked our type and this is for doing statistics in statistics you have things which are categorically a categorical variables and those in R are represented by a factor so a factor is created by using the keyword factor and then I make a combination so I first repeat the word male 20 times and then I combine this with a repeat of the word female 30 times and then this makes a vector a character vector containing male 20 times and then female 30 times and then I say make it a factor and what factor will do it is underwater it will now treat this as a categorical variable of two levels right so things that you want want to add to gender have to be male or have to be female you can't put any other value in there because then it will throw an error and will say well you're not allowed so it's it's kind of a factor allows you to create kind of your own create a type which has a very specific amount of possibilities in other languages like Java or C++ this is called an enumeration so an anum but in R it's called a factor because of of statistics in statistics we often deal with different factors and different factor levels so a factor is treated very differently from a numerical value when we start doing things like linear modeling and of course there are comments so comments start with a hashtag R will ignore these and you should use them often so if you write a script use comments I would say for a beginning programmer and even for more advanced programmers you want to have at least one comment per three to five lines of code so every three to five lines of code that you write you write a comment well after it or above it explaining what the code below does so that other people know what is happening I also often use comments during the assignments when I want to have an answer right so I have the code and then the answer I prepend a hashtag to the answer and then I can write for example my observation or I can write the answer from from the code alright so those are more advanced types alright my favorite part what is the type of and now this is your your time to shine so the first one what is this what is the type is it a logical and numeric a character a data frame a list if I just type this in R what would it be and I'm counting on you guys to all participate and who wants to go first no one everyone just woke up at their keyboard like oh my god what's happening we have to type something we have to alright Alexander Billy F says logical Jan Haga says logical any more answers I'm still waiting for the correct answer though this is this is to trick you guys right so this first first thing here this true is a character it is surrounded by these air quotes right and everything between an air quote is a character so because you use the the like double quote true to define a character alright Sandra just comes up with character yes yes it is a character because it's surrounded by the quotes right so it's it's like coding requires eye for detail so a single quote somewhere can completely change the meaning of your code alright so very good like at least three people participated would be nice to have some more participation but I'll take it so the second one I'll wait like is it a character a logical and numeric don't be shy like same story yes same story indeed yeah character very good very good character yeah it is indeed a character yeah because it's surrounded by the by the double quotes alright so what is the third one one e plus 11 what is this what is the type of this numerical yeah it's it's a numeric value num numerical it's numeric not with the AL I can be a stickler for these things on the on the assignments so or not so much the assignments but also in the exam like in R it there's no type called numerical it's called numeric so like it's not wrong it's just it's not correct and just an other tip I often ask for lists so for example if I would ask name four things if you would name five or three then the answer is wrong because like you should read the question if the question asks for three reasons to do something and you write down four reasons then I'm not gonna choose for you it's just wrong you didn't understand the question so and I can be a stickler for these kinds of things I generally am very generous so I try to kind of read like the answer that people give in the best intention but if I'm asking for three reasons and people write down four then it's definitely wrong it's just something that yeah alright so the next one number four on the list what is the type or of this 0x89 come on people you can do this good to know yeah young it's good to know I'm generally very generous so if you if you if you make a little rounding error or or like you these kinds of things and a and a that's that's an interesting why do you think it's an a on alexander says numeric any other guesses for what it is it is indeed a numerical value shown them yeah it's numerical and that is because it's written down in hexadecimals so 0x89 is actually not the number 89 I have to actually type it into our to figure out what it is but 0x89 is actually a hundred and thirty-seven is extra variable or multiplication no it's not it's just the way that you write down hexadecimal numbers so you would go so something like this so 0x0f this is actually the number 15 in computer language so you you go from so numeric or so hexadecimals go if you count in hexadecimals you count like 0 1 2 3 4 5 6 7 8 9 a b c d e and f and then you start with 10 11 12 13 14 15 16 17 18 19 1 a 1 b 1 c 1 d 1 e 1 f 20 numerical or hexadecimal values you use them when you're calculating things like bits and megabytes and these kinds of things it's how these people that sell you a 1 terabyte hard drive always screw you over and don't give you a terabyte right they give you 1 billion bytes which is not a terabyte because actually a megabyte is actually 1024 times 1024 officially so but it's a hexadecimal number so it is still a number so 0x89 is actually a hundred and thirty-seven so it is a numerical value it's just a numerical value all right let's do the let's do the next one what do we think is the next one and this again is a is a tricky one but I'm hoping that you guys will get it correct all right we get two different answers so we get a comment and then a vector or a character it is a comment everything starting with a hashtag afterwards is a comment if people come from a background where the normal thing that people say to this is when they when they have a little bit of html or CSS experience they will say this is a color and it is in theory a color but not if you write it like this so our get this is an RGB color so this would mean full red no blue and middle green or slightly above middle green but because of the hashtag it's a comment in our so our doesn't recognize numbers this way you can specify colors in our using the standard kind of hexadecimal coding of colors but you have to do it differently I'm not going to tell you how but you can look it up all right then let's do this one the one to last as factor true what is the type it's bright pink yeah I know it's bright pink I chose it because it's bright pink all right come on people like what is it as fucked or true no one no one come on you know this you know this you skip the false yeah I skip the false I know I skip the false like that's a logical value right like it's this one and then it's just not quoted so it's just logical I know I skip the false like like by now people should be kind of like there's like I'm trying to trick people right this is this is this is my favorite question to ask on the R exam generally we have like the whole R exam is just nothing else than guessing the type of different different different structures and then I make them make them as difficult as possible Jan Hager says categorical value yes it is so this one here as factor true so you take a logical factor so you take a logical value right and then you force it to be a factor so it is it becomes then a factor value because that's what you ask it to right so it could be that the value of it is NA because it cannot transform it into a factor but still the thing the class of the thing that comes out is a factor all right so is character one e plus 11 all right come on people this one this one's really tricky right normally in the our course like when I do the R exam I try to make them like almost a page long right so it's like going from left to right and then people have to kind of figure out oh my god what's happening here and how are all the conversions going and and it's just nice right you can't truly understand how complex and insane the type system is from R until you've turned a 5 into a 3 and that you can actually do that like by programming in R you can turn a 5 into a 3 and you already have all the tools to do that so one more then we can then we can continue I can then show okay my moderator says logical with a question mark are there any other guesses like don't be shy don't be shy come on I won't blame you for it there's no points there's no like I might revoke your your VIP status if you have it wrong but that's about it that's that's the maximum that I can do like you're in your safe home environment like I can't hit you with a stick which I would normally do when we do live lectures so all right we get a character and a numerical and then another character all right all of a sudden like people are really interested all right so this is a logical value and why is it a logical value well it is a numeric value right and then I'm asking is this a character to which the answer is false it is not a character so the thing is it this whole statement is nothing more than just false and the class of false is logical so it is it is it's just a question so it will it will give me a boolean answer yes or no and a boolean is a is a logical value all right I hope you guys like this should we do a quick intermezzo I think we do a quick intermezzo I want to I want to show you something in our alright so in our right we can do lists I told you guys that we can do lists in our so I can do C and then I can do one two three four five six seven right and this is all numeric so now let's do something else and let's start turning for example a five into a three so I make a little list and I call this V1 and I put the numbers three four five in here like this right so when I type V1 I get three four five yeah yeah it is it is it is really the type system in our will it will screw you over I've been programming in our for like 12 years and it's still like on a daily basis like surprises me so now we have something which contains three four five right so how are we going to trick the R type system into making this into one two three well the the answer is here use the route to make it factorial right be factorials it tries to encode in the smartest way possible so if I say as factor of V1 right then it will now show me three four five so it's still correct and then it says that there are three levels three levels called three four and five but now there's a disconnect because underwater R tries to be smart I told you it saves everything in RAM memory right so it tries to be smart and save from memory so how it codes this is actually it codes this one as one this one is two and this one is three and then it just has like an additional lookup table called levels which it then couples the first level is three the second level is four and the third level is five so if I take this as factor and I do then do an as numeric on it right then now all of a sudden are just start surprising everyone because now it's just one two three so I changed three four five into one two three just by switching the type system right from numeric to factor back to numeric so the type system in R is not it's not congruent right so so it's not in the inverse of each other going from numeric via factor back to numeric is not so how do you actually make it back into three four five well there's there's you have to then go to a higher type right because the factor is a type which is between the logical and the numerical values but you can go via the s character right if we go via the s character then now it will be three four five again so we take a numeric value make it into a factor underwater R starts saving memory coding it as zero or coding it as one two three with a lookup table then when we do an s character on it it transforms them back into characters but now we have to transform them back to numeric so this is the way that you can just completely get like completely mind boggled by the R system or R type system all right master flexi as factor as numeric as factor v1 yeah then it will code it as one two three with the the levels one two three right so it's just an s factor and then you want to do an as numeric as factor right yeah one two three levels one two three it's it's really really difficult and then there's one other thing which is really tricky and that is the strings as factor because generally in the older versions of R this was set to true so when you would load in a data set and you would have a column right and this column would obviously be a character column if there would be the same character twice it would directly start transforming it into a factor and then in the newer version of R they put this to false so that means that they broke like 10 years of code which was actually dealing with this weird transformation on the bottom to now have it being like well more or less what people expect but it's still very difficult so trust me like the type system in R it will it will definitely screw you over many many many many times every like every three to five days I run into something and it's just so always check and especially when it says levels as soon as it starts saying levels you have to really really like pay attention like does this does this really do I really want this to a categorical variable but it saves a lot of memory space and that used to be a big issue in R is memory all right back to the PowerPoint back to learning new stuff all right so this is fun right are we enjoying ourselves are you not entertained all right so a list lists are again one of these mind-boggling things so in R you have the single bracket right so if you want to index a vector or if you want to index a matrix then you use the square bracket singular but if you want to do a list then you have to use the double bracket and why that is there's a good reason why that is and that is since a list can contain anything so here I'm making a list called W right so it has name Fred then the numbers are 1 2 3 4 then I put the age in again and now I put a whole matrix in the fourth position right so I put a matrix which is 1 0 0 1 number of rows 2 number of columns is also 2 all right it's good that you're entertained I find this highly entertaining as well like I've done this on many conferences and especially the list with things to guess right like I've never been into a crowd even when I've had crowds which are there for like I did the list in Kings College at an advanced our programming course where I was teaching like a one-day exercise and even people we've been working with our for 30 years they would make errors in these small like statements and it's it's very very funny and it it's hard like like the only reason why I know the answer is because I type them in and ask for the class in R good so a list lists are even more more of a mind mind thing so a list I just make a list when I type W right so I store it in a variable called W when I type W I see here my my list right so a list can contain anything literally anything it it can't even contain a reference to itself which makes it just like a circular list but in this case it's a relatively short list it has four elements first element is a character vector the second element is numbers so a numerical vector this one is also a numerical vector just contains one element and in here we have the matrix so if we want to select from a list we can do it in two ways we can use the double square bracket and then specify which element we want from the list and then I still have to specify this give me the first element right because otherwise I would get back a vector which contains a character Fred but if I want to select Fred as a singular character value then I have to select from W from the first element of W which is called which has the name name I can then select the first fortunately you don't have to always use the double brackets because I gave it names right so I gave each each element of the list name I can also use W dollar numbers and then from that I want to select the second and the third element so then it selects this two and three from numbers and of course this is not the two and these are the indexes and these are the numbers that I get back right if this would be one one one one then this would give me back two ones instead of two and three I can also say something like from W give me the fourth element of the list and then give me from the thing that you get back the first column so it will give me the first column of the fourth element in W and of course I can do the same thing by using the dollar sign so I can say W dollar matrix so from the thing called matrix give me one comma so these these things look really neat right so why would you ever want to use the double square bracket thingy and why would you not always give it names well sometimes you have duplicate names and a list can actually have duplicate names for some inexplicable reason they allow to have duplicate names in a list and that happens especially when you're combining multiple lists so in this case it then you can only use the brackets to select the thing that you want because if you do W matrix and there's two elements called matrix you will get just the first one back and not the second one if you want to get the second one then you have to explicitly give the ordering at which it is in the list all right so some some additional functions for matrices in data frame you can ask for for example the number of rows of a matrix the number of columns of a matrix row names and call names are interesting because they are functions which give you back the row names or the column names but you can also assign to them so I can say if I have a matrix which has three rows and three columns I can actually put the names on there like this so it allows it's a getter and it's a setter function so I can actually assign new row names to the matrix I can also transpose the matrix so that I can use the t function to transpose a matrix which means that everything which used to be in columns is now in the rows and everything which was in the rows is now in the column so it just takes the matrix and flips it on its side so I haven't made I found this really nice image about a matrix and it's transposed so you can see here that column number one in the transposes row number one and this you use a lot in computer programming I don't know why but matrices always are the wrong way around for example the boxplot function it plots the columns right so if you would have if you would have the matrix row wise right if you would do the log 2 on one so using the apply to the matrix comma 1 comma something then you have to transpose it before making the boxplot otherwise you would have like a gazillion box plots next to each other and it would take half an hour to plot that and you can actually not really interrupt the plotting routine in R which is a little bit of a shame so if you make a mistake in a plotting routine and you say plot the 60 million elements then it will just do that and you will just have to wait or kill the entire R session so transposing your matrix making rows into columns and columns into rows alright we've already seen variables but I want to tell you a little bit more about variables so variables are in my mind boxes so a variable is a box and you can put stuff in a box and in R you can do that in two ways you can use this arrow or you can use the is so the is is there and it's just the assignment I generally tend to prefer the arrow when I first define a variable when I then update the variable I tend to prefer the is so in R if I would write a little piece of code let's go back to the R window actually so when I would define a new variable I would say new var is for example a and now when I when I'm in my script and I'm updating it then I would say new var is and then I would assign a new value to it and this is of course this this doesn't have to be but the arrows allow you to also do something else which is more useful so if I'm for example having a vector right and I'm defining my vector and at this point I don't want to go all the way to the front and then do the arrow and assign it to somewhere I can also use the arrow the other way around and in and put it into new var 2 right so I can also assign the other way and when you're typing code this sometimes comes in handy so the arrow allows you to go like both ways while the is only assigns to to the left side good so arrows useful and again there's two there's actually more arrows that you can use but anyway so variables in my mind are boxes and you can put stuff in and you don't know you can use the box and you have without knowing what is in it so you can just put something in and I don't care if it's a list or a or a data frame I can in the end inspect the box and see if it is a list or a matrix or a data frame but all right so words in the middle I put this in to know when we are at around half of the presentation so I don't think we will finish the whole presentation today but clean code is clean scripts always try to work as clean as possible a lot of you come from like a laboratory setting and also there you want to work as clean as possible so I have for example when I do my assignments for the lectures and I'm hoping when you do the assignments that you use a new file for a new lecture name files in a logical way so call them assignments one dot r assignments two dot r or even better would be answers lecture one or answers assignment to or something like that right but it's up to you to create structure I always try to add a header in the comment section for each file like I showed you right so for example if I look at my if I look at my answer then I always have something like this on top just to know these are the answers to the assignments of lecture four and it's written by me I would advise you to always do this and when you do this also put your name there right so make the name the date so today is the third of December 2020 state the purpose of the file and add a copyright statement and this will save your ass sometimes I've had people stealing my code pretending it was theirs and they can change the header but if you take a header and you combine it with version control something like hit or other version control which kind of cryptographically signs your your changes and then puts them on a repository online this can really help in case you other people steal your code or someone sues you for copyright infringement of stuff that they think they invented but you actually did so very very big tip is if you make a new file and you put code in that file always add a header the name the date the purpose of the file the copyright statement how do I want other people to use my code even if you don't want other people to use your code just say that it's copyrighted by me and it's it's my private intelligent where can you put it online so I always use github which is nowadays owned by Microsoft so but then you have to use hit so you have to use a version control system which digitally signs your commits so every time that you make a change to the file you make a commit and then I put it online for everyone to see so if you want to look at the code that that I made let me get my so here you can find more or less all of my code where where I'm working on so I always use github there's many of these you have also have hit lap and you have mercurial you have as SVN and there's a lot of different version control systems so find one which works for you I always use github just because I've I've been used to it and I've been using it for seven years and I actually still pay for it it actually it went from being a paid system to when Microsoft bought it to a free system but it still pays seven seven euros a month for it just because I like supporting Microsoft and you should support Microsoft any way you can like with Apple and like the other kind of big companies like Google and stuff like screwing them over all the time I like Windows as well so just just pay for it so that things that you can find here are for example the web server I wrote CTL mapping G network to so all of the projects that I that I worked on or contributed to and I just put it online and in the case that someone steals your code then you have proof right I can I can show for example that when I started writing my web server the first commit I made was in 2013 at a certain date and it's cryptographically signed by my private key so people know that it's that it's mine but put the header there so that everyone knows if they can or cannot use your code and of course I'm a big fan of open source software so always put stuff under LG PL 3 or something yeah an alternative to github is bit bucket you also have github which people are very lyrical about so you don't have to make a github account and but you can you can use anything that you want alright as an example this is for example something that I wrote so it's the analysis of Hardy Weinberg equilibrium so this is the purpose of the file it is copyrighted by 2015 by the how Berlin since I work for the how Berlin they automatically kind of own the copyright that I write during work time it was written by me it was last modified in April of 2015 and it was first written in February 2015 and like I said all my scripts start with a set working directory so it it just moves to a file on the hard drive on my hard drive so I know exactly where to solve yeah so also works with hit or me curial yeah there's a lot of a lot of version control systems out there some of them are difficult to use some of them are easier to use but I like it it takes it takes like half a year to really get into it and understand it and to use it on a day-to-day basis but you should you should all right so clean code we will go back one of the things that I always advise people is also to use a good text editor so on windows I always advise people to use notepad plus plus the window that you're seeing here when I'm when I'm showing you code is notepad plus plus one of the nice things about this I pressed the button which I shouldn't have pressed but what I like is that for example when I open let's open some code which is relatively nice so most of the code that you actually are looking at is code highlighted so it didn't code highlight the answers here because I saved it as a text file but if you open up a file then it has like this whole list of languages that I actually that it actually understands so here you can see that it highlights things like comments in in green numbers are in orange so you can directly see that it's a number strings here are highlighted in in gray and for example some keywords are highlighted in in blue so that you know oh you're creating a new object and head like the while and if statements they are they are highlighted so they have a slightly different color from the rest which is good so hey you can physically look at the code and this of course clean code is nice code you can see that there's no copyright statement here and this is because I'm still working on a code and it's still private this is this is my private code and I put it on github so it's all tracked and and there's a copyright statement I think in the main repository so I didn't put one on top of every file because this project is like 500 files big so it's I don't always follow my own advice which I shoot more often actually so but yeah head so use code code that looks good is easy to maintain so if you get back to code and you have everything nice like hey when you do a while you do a space and then you do this stuff in between and then you do your bracket and one of the things that notepad plus plus also has a test bracket highlighting so when I click on a bracket I can automatically see where the bracket is closed so it's opened here and it's closed here and for example this one here is opened here and it's closed here the same thing it would do for these ones so hey it just allows me to visually look at the code and work with it so back to the PowerPoints don't show you any secret code that I'm writing but when you use Windows use notepad plus plus it's it's without a doubt in all the dozens of years but if you put it on github people can access it right so what if they steal the idea not the code that's fine right ideas are not I have an idea every time that I go to the toilet and that's not copyright protected or anything only code is implementation of ideas are protected ideas themselves are not protected at all and ideas are just nothing they don't exist just in your mind and github actually allows you private repositories so some of my repositories on github are private so you can't look into it only I can only when you have the proper authorization I can still add people to these private repositories so I can work together with other people on code but no one outside of our little group can see it and of course they can steal the idea like you like Facebook is a very simple idea right you could steal the idea of Facebook but try and getting it being as popular as the real Facebook is going to be an issue like that's gonna be hard on OS X text Wrangler actually I think this is outdated because text Wrangler doesn't exist anymore let me see what the current name of it is text Wrangler is now called BB edit so on OS X use BB edit not text Wrangler text Wrangler is old Linux if you're if you're working in coding on Linux if you're smart enough to install Linux then you can use whatever the hell you want you're good enough to using computers to figure out what is a good text editor so most importantly if you if you want to use a good text editor make sure that there's code highlight thing like I showed you that it highlights like strings different from numbers from from keywords and that it supports bracket testing bracket testing is going to save your noodle or whatever you want to call it because head you can easily see where stuff starts and ends and some will also warn you when something is missing although I do not like text editors which force me to which when you click an open bracket it automatically introduces a closing bracket something like atom or visual studio code does that I hate that I I don't like text editors to put additional brackets so closing brackets for me I don't like that but I want them to highlight it so I can see where it ends all right so like I said clean code is smart code so here for example you see the exact same code twice but this is just a confusing mess right you can't see what is what and here you have a nice unordered list with list items and then in the last list item you have like a sub indentation is everything code follows a structure and and align it in that structure don't type anything everything on one one line you can also in our you can just use dot comma and then type the next statement use dot comma type the next statement so you can put everything on one line making the line like a million characters long but that's not going to help you so so make code clean make it make it structured all right then we're going to take a short break and then when I come back we will talk about control structures which in my mind have since variables are boxes control structures are conveyor belts bringing bringing a box from place a to place b so they guide boxes to their correct destination based on a fixed algorithm so we will talk about that after the break so I will I will start the second break so let me stop