 I started the recording, so we're live, also for the people that watch it back on Moodle. So there was a question by Risfan. I like the GIFs. Will you say something about when and where you upload the PPT and task homework? So the assignments and the lecture, the PowerPoint and stuff I will upload today. So you can start directly after the lecture. The recording will not include the GIFs. So if you want the funny GIFs, you have to come to the Twitch lecture. So that's kind of the stick that I have to force you to do it. Oh yeah, sure, sure. I will make a note and I will upload them beforehand. Alright, yeah. No, that's easier for you guys. The lectures will also be saved by Twitch, so you can watch them back for 14 days, I think, after which they get automatically deleted. One of the nice things about watching the lectures on Twitch is that you also get the chat on the side. So the local recording doesn't have the chat, so that's why I kind of read out some of the questions so that when people watch it later on Moodle, they can also know what the question was that I'm answering. Alright, so the look and feel of R, this is how it looks on my Windows 7 machine. This is how it looks currently on my machine. So I'm using just the standard R. I'm generally not using the RStudio. Although if you want to use RStudio, that's fine with me. I generally use a system where I use R and I just use Notepad++. So this is my programming window and then here I have the execution of the program because I like to keep those two things separate. The reason why that is is because originally I started programming in C. What is the difference between R and RStudio? There is no difference. RStudio is a shell around R and that's all it is. It has a built-in text editor, but I don't like the text editor in RStudio because I like Notepad++. It has syntax highlighting and brackets and these kinds of things. I think the newer versions of RStudio have that as well. General Gulak, would you recommend RStudio for us beginners? No, I would actually advise against using RStudio. RStudio is easy in a way because it has this additional window where you can see which objects are loaded and you can load libraries by just clicking on it. The main issue that I have with RStudio is that it makes it really easy to create scripts which are not reproducible because if you click on loading a library, then you generally don't type in that you need to load the library. Can we use RStudio? Yes, of course. You can use RStudio. You could use R in the command line if you want. Programming in R is nothing more than writing a text document. It's just writing something like, okay, so I want to load a certain library, for example, a library that allows me to do QTL mapping, then I want to set my working directory somewhere, so I want to go somewhere on my hard drive, for example, in the D drive, and then I am going to read something, so I'm going to use read table to load in data.csv or something, right? And then I have to say separator equals comma because it's a comma separated file. The thing is, is that in RStudio you can load something by just clicking and dragging it, but then it's not in the script, and one of these things about programming for scientific work is that everything needs to be reproducible, and what I generally do is I type the script that I want, and then I just do Ctrl A, Ctrl C, then I switch to R, and this of course will create errors because I don't have a file which is called data.csv, and then I just paste it in, and then of course it will give me an error because this file doesn't exist, but that's the way that I do programming, and this forces me to keep the script in such a way that it will kind of run from beginning to end without any errors. And RStudio, it has its advantages, especially for beginners, because you can go back and forth when you have multiple plots, and you can click on loading a library, but this makes so that you can create scripts which are not... By writing a script, I always include the library like in LaTeCh. Yeah, yeah, yeah, and the thing is you need to write down which libraries you load, and in RStudio you can just click these libraries, and then it can even save these, so next time that you start RStudio it already loaded those libraries, so you're not going to add that to your script, so in a way it forgets the dependencies, right? If you move to another computer, which has a different setup of RStudio, it might be that your script is now starting to produce errors because you did not load the library that you require, and that's why I generally advise people to start with just using a basic text editor, something like Notepad++, and the nice thing about... For didactic reasons, kind of. Generally RStudio is really good when up until you reach a certain point, but could you not control that by using Anaconda? Yeah, but then you're using an extract, and then your scripts will only work when people have Anaconda installed, and it's not reproducible, right? Reproducible research means that you have a script, you have data, and by having these two things you can run the whole analysis, so there's a... And one of the nice things about Notepad++, which I love to use, especially under Windows, is that you have like, bracket highlighting. So if I select the bracket, it will highlight the corresponding one. So if I make a mistake and close this one, which is not opened, then now I directly know, because it doesn't highlight... So I know that I've missed the bracket somewhere. Why Notepad++? That's kind of irrelevant. You can use any text editor, just don't use the standard Notepad that comes with Windows because that one's really, really poor, and doesn't support these things. One of the nice things is, is that if I would save this file, let me save it somewhere, and I say script.r, and just save it here. Whoa. Yeah, yeah, yeah, just save it there. It will also highlight keywords. So it will color keywords that it recognizes, and it will color also things like the start and the end of a string. But yeah, there's many ways to do r, and the nice thing about doing it in a separate text editor is that when you start using external computers, so for example, you have a script which uses like a lot of memory, or requires you to have like 30 CPU cores, then you can easily copy-paste the script into a terminal window, and run the script on another computer, and not your local machine. And that is where things like RStudio really start becoming a drawback. But I ain't forcing you to do, you can do whatever you want, right? That's programming, so you have to find the structure that works best for you. But the structure that works best for me is just having a separate script where I type my code, and then copy-pasting it into R. And then once I copy-pasted it, I actually close R to make sure that I don't have variables floating around. And this happens, for example, when you do something like x equals 5, and then hey, you now have like 30 or 40 additional lines of code, and then you start using x. At that point, it might be that it's saved in your session or other problems. So in my mind, scripts are different from data, so scripts are written in the text editor. Data is either made by Excel files or other text files, or like getting it online. So I try to keep these things separate. Not only that, but when I make a script, I always put in a header. So I always say something like this, so a script as an example on how to create a script. And I always add something like Denny Arans 2021, Berlin. And I add a copyright sign in front, so just that people know who did it, when it was done, and which company or which thing I worked for. And this is of course, do you need to close, or is there also clear command? There actually is a clear command. So you can use, remove all objects, which is the command this. And this thing is good to always put as the first line, because then it clears the entire R session of everything that there is, and then you start off with a fresh R session. So you don't have to close it every time, but I generally tend to close it. And that's just to kind of prevent things which are from an older session or from another script. Because when you're working on big projects, you might have like five or six different scripts, which you run one behind another. And then of course, like my scripts, or when I think about good scripts, it starts by loading the libraries, setting where you are on your computer, so the working directory, loading in data. And then generally, the last line of my script is something like a write table, where I write out the data after I've done all my manipulations. And that is kind of the way that I work. And I found that this works very well, especially if you, because it forces you to write down everything that you do. So I treat programming as having a lab book, where you write everything down, that's the script. And then you have your workbench, where you do the stuff, and that is the R window. So this is my lab book, and this is my experiment. And that's kind of how I try to separate those two. But of course, if you want to use RStudio, because you think that the editor in RStudio is much nicer, then be my guest. I've seen people program R in different environments as well, and they are pretty good programmer. All right, thanks for the explanation. Could you suggest a good alternative for Notepad Plus Plus for Mac? It's in the lecture at the end. Let me look it up, because it used to be called Text Wrangler. But I think it got renamed to BB Edit. Let me check. Yeah, it's now called BB Edit. So for Mac, use BB Edit. And if you're on Linux, then use whatever you want. Like, if you're capable enough to install Linux on your own, then you don't need any advice for me on what kind of a text editor to use. So BB Edit for Mac. Should be free, so no problem, Giorgio. All right, so let's, what about Jupyter Notebooks? Really useful. I know some people who are massive fans for Jupyter Notebooks. And it works really well, because it also forces you to write documentation. Jupyter Notebooks, you used to have similar things in R, which was called SWEVE. And that is, then you make a latech type document. So latech is a markup language, like HTML. And SWEVE allowed you to put the text so you can just write text. And then you can do an R computation, and then only show, for example, the figure that comes out. And SWEVE allowed you to go and have some text and some R code and then directly generate a PDF. But like I said, you're free to use what you want. And in the end, it doesn't really matter, because you're always talking to the R interpreter. And the R interpreter doesn't change. It doesn't matter if you use Jupyter Notebooks, or if you use RStudio, or if you use R. What is the source to download Notepad++? I always just Google Notepad++ download. And then it's the first, it's HTTPS notepad-minus-minus-plus.org. And get the 64-bit release, just so that it can handle like massive files. I can put the link in the chat, probably. Thank you, moderator. That's why we have a moderator to do these kinds of things. All right, let's switch back to the lecture, so that we don't spend like hours on the first lecture. So this is the look and feel. Depending on what you use might look very different, but it always consists of these two essential part. One of them is the console. So the console is where you can talk to the R interpreter. And you have your graphic device, which shows things like plots, or heatmaps, or whatever you want to visualize. And this is what I mean by one of the advantages of R. R has built in graphics. So the graphics, they are built into R, and R understands what a figure is, and what the x-axis is, or the y-axis. So it knows this, and it's built into the programming language. All right, so let's start some first basic programming, right? So we can use R as a basic calculator. So if I type in 1 plus 4, it will tell me 5. So I can show you a little bit of an example of that. So let's clear the window, just so that we don't have the... Yeah, why not? Just do it like this, right? Then you can't see the error anymore. So hey, if I would type in 4 plus 1, it will say 5. So hey, you can use R as a... Can you repeat the notepad plus plus version? It depends on which computer you are using, but there is, I think, a 32-bit and a 64-bit. And nowadays, people almost always have a 64-bit computer. This allows you to use more memory. So if you have a file, which is one gigabyte big, then the 32-bit version will not open it, while the 64-bit version will allow you to open it, because it's just bigger. But I have a Firefox window here as well, so we can go to the download. And then you just say, well, I want to have the latest release, of course, and then here it automatically defaults to the 32-bit version. You don't want the 32-bit version. You want to have the 64-bit version. Of course, this depends on your operating system. But the operating... If you're on Windows, it will tell you that 64-bits is not supported by your system. So you can't install the wrong version, and the 32-bit version will work on a 64-bit Windows as well. So you can just get the installer, double-click, next, next, next finish, and then you've it installed. All right, so let's move back. So just a basic calculator. So the R interpreter understand basic mathematics. Remember that the decimal separator in R, so separating like whole numbers from fractions of a number, is always the period in R and never the comma. So 5 comma 3, although in Europe this is very common to do, right? It uses the American system. So it's 5.3 for 5 and 3 tenths. There are some special operators, like if you want to do the exponent, then you can do 5 and then this square heading 2, or you can do 5 multiply, multiply 2. And this is then 5 to the power of 2, which is 25, of course. It supports Euclidean division and the Euclidean division remainder. These are always difficult for people, but Euclidean division and Euclidean division remainder occur a lot in computer science, and there's a next slide which will explain what the Euclidean division is and what the Euclidean division remainder is. R also has some special numerical constants. So you can have inf, which stands for infinite, and there are two types of it. There's positive infinity and negative infinity. You have NaN, which is not a number. So when you are trying to convert the letter c into a number, then it will say NaN, not a number. And R understands what a missing value is. So Na, the Na value is a missing value, and this is significant when you do statistics. If you do statistics, then the statistics change based on missing values. If you calculate the mean, then the mean is based on summing up all the numbers divided by the number of numbers. If you have a missing value, then R can deal with that. So instead of having five values and a missing value, so it will recognize that there's a missing value and do divide by six instead of divide by five. So hey, it knows that a value can be missing. Na's propagate. So if you do something which results in an Na, then having an Na plus something will still be Na. And this is kind of a safety thing so that when you are dealing with missing values, you as a programmer are forced to properly handle missing values, which is really nice. And not all programming languages have this, especially the NaN is not very common. And something like C cannot have integer values being missing. Floating point values have their own missing, but integers cannot be missing, but in R they can be missing. So it understands what a missing value is. All right, so Euclidean division. I don't know if people had this, but Euclidean division is very similar to long division, which when I was in elementary school and in high school, we were taught to do divisions this way. I know that nowadays they don't do this anymore. But imagine that we want to divide 100 by 39, right? Then how I was taught to write this down is say, well, we have 39, which is the divisor, then we have 100. So that's the number that we want to divide and we put these brackets around it. And the example would be better when we had 1000. But what you do is you try to say, well, one is not divisible by 39. 10 is also not divisible by 39. 100, you can divide by 39. And 39 fits into 100 two times, right? So what you would do is you would then write down the two here. And two times 39 is 78. And then when you subtract 78 from 100, you get 22. And the two, so the amount of times that 39 fits wholly in 100 is called the Euclidean divisor. And 22 is what remains after doing this division. Is that clear? I hope so. It comes back a lot in computer science. It's not something that you would be confronted with the first two or three lectures, but it is something which is relatively, it comes back a lot. For some reason in computer science, you often work with Euclidean division and not floating point division, right? Floating point division would say two points something. But in this case, you want to know how often something is in the number wholly. And when you do that, how much is left? There are more things which are built into R. So there are built in character constants. So letters in R are the 26 uppercase letters of the Roman alphabet. So you have letters written with small letters, and those are the 26 lowercase letters of the Roman alphabet. R understands what a date and a time is. It also understands what a month is. It knows that January is the first month and February the second month. So month.abb is the three letter abbreviations for the English month names. And if you want to have the full name of the month, you can use month.name. Furthermore, R has a whole bunch of built in constants, things like pi and E, and these kinds of kind of magical numbers. And pi, I hope that everyone knows that two times pi times R is the circumference of a circle. And so pi is the ratio of the circumference of a circle to its diameter. So two times pi times R is actually pi times the diameter. So you can do circle calculations and these things as well. One of the things that I want to point out here, because I saw that in the assignments, it often goes wrong. So letters is just a vector. So if I want to know what, for example, the 16th letter is of the alphabet, I can just do this. So I can use the square brackets to select from a vector. So here from the vector letters, I select the 16th letter, which is the letter P, capital, because I'm using capital letters. So remember that these built in constants are just vectors. We will come back to two vectors during the rest of the lecture, but so that you know that you can select from them just like you can select from any vector in R. R also support imaginary numbers. So in case you are doing things with springs and spring constants, then using imaginary numbers is necessary to calculate some stuff. It doesn't support it directly. So if I ask R what the square root of minus one is, it will say that the square root of minus one is not a number. But if I ask for the square root of minus one plus zero imaginary part, then it will say that oh, the square root of minus one is I. So it understands imaginary numbers and it allows you to compute with imaginary numbers. And this is very useful when you are doing mathematics, which goes into things like spring constants. So if I have a spring with a little weight on there and I pull it and it goes up and down, then to calculate the dampening of the wave, you need to use imaginary numbers. So it can understand that, but you have to force it. So you have to be explicit that you want to use it. So normally it will say, no, it's not a number, but you can do this. It supports all basic trigonometry functions like sine, cosine, tangent, R cosine, R and these kinds of things. And it can do logarithms. So the thing that you have to remember is that normally we would write ln of five for the natural logarithm. So log five is two point something. So you use the two point something base. So the natural logarithm. So the E value. If you want to have a base 10 logarithm of five, you have to explicitly say the log 10 of five. So this is a little bit confusing because many people on your pocket calculator, it has a button which has log and then the log button is the log 10 and it has a button which is called ln and this ln button is the natural logarithm. So in R, the log is actually the natural logarithm. If you want to have the log base 10, then you have to type in log 10 of five. And the inverse, of course, is called xp for exponent, which is e to the power of one in this case. So if you want to have e to the power of 15, you can just type xp15. And it will come back later on. It's not that important now. It's just that you know and that you get a little bit familiar with all the options. So imaginary numbers are supported, trigonometry is all supported, and logarithms are also supported. Operator precedence. So the order of operations is very similar to normal mathematics. We first do exponents and roots, then we do multiplication and division and then addition and subtraction. And it follows the standard PEMDAS system. There's probably a German version of the PEMDAS. So in English you get taught that PEMDAS are please excuse my dear Anne Selly. So this stands for power, exponents, multiplication, division, addition, subtraction. And question to you guys. If I have this 10 minus three times two, what is the answer of this? These are these things that you see on Facebook, right? Your aunt on Facebook does these things. All right, so four, four, four, four, good. Yeah, that's pretty good. So no one comes up with 14. Like on Facebook, like 50% of people just fill in 14 for some reason, because they don't understand operator preference. But like you first do the multiplication and then you do the subtraction. All right, so that's how this works. You can always overwrite operator precedence by using brackets. So if I really want to do the minus first, then I would say round bracket open, 10 minus three, round bracket close times two, and then it will first do the, so you can always override it. Short break. So we're a little bit behind. So I will try and speed up a little bit. But so there's a lot of things in R. So in R, when you start R, you start a session. And the session is something that is, that is holding everything that you load. In R, everything that you load goes into your RAM memory. So if you have a computer, which has four gigabytes of RAM, then you can only load in four gigabytes of data in R. And this is one of these drawbacks of R, is that it is like Google Chrome, it will eat your memory, and it will eat your memory quick. And depending on which version of R you installed, you have a certain amount of memory that you can use. And this is also dependent on your, this is also dependent on the data that you load. So the size of the data, the type of the data. So characters take a little bit more than, for example, integers. But remember that everything is in your random access memory. There are some functions that you can use to manage your session. So you can do get working directory. And this will tell you where you currently are on your hard drive. You can do there, which will give you the files, which will give you the files that are there. So hey, I can go to my D drive and I can ask which files are located here. If I want to move to another position on my hard drive, so to a different folder or to a different different hard drive, I can use the set working directory. And the ls function shows you which variables are currently loaded in your session. So let me give you a small and quick example of that. So when we go to the R session, I can define, for example, something like x, right? And I can set my working directory to be on my D drive. Now I'm at my D drive and now I can do something like deer. And this will show me the files that are there. So there's a recycle bin. I have a backup of the USB stick of Gudrun that I got. I have a recycler, which is similar to the recycle bin. And I have some kind of a text file here. Then I have two folders called D drive and E drive, and I have a recovery folder, right? So I can also go into these folders by setting my working directory, for example, like this. And now when I do a deer, you can see what is there. So I have like several folders. One is called for Manuel. I have like a G big folder and like a so and these kinds of things. If I want to know which variables I have already defined, I can use the ls function. So when I use the ls function, I see that there's one variable defined and this variable is called x. I can of course define more variables. So I could define y being seven, and then I can define seven being nine, right? And now when I do ls, it shows me that I have three variables defined called x, y, and z. So the ls shows you what is in your session. The deer shows you what is on the hard drive. If I want to know where I am on the hard drive, I can do a get working directory. And this will show me I'm at the D hard drive in Windows. And then I'm in the folder called D drive. The reason why I have D and E separated is because of historical reasons. So don't worry about that. In your hard drive, it will look different. If you want to install a package, you can use the function install.packages. For example, the QTL package for quantitative trade locus mapping. But like I said, there are more than 4000 packages in the standard R repository. There are literally hundreds of thousands of packages for R, which are created. And during the lecture series, we will actually create our own package as well. Installing a package does nothing. It just gets it from online, installs it on your computer, and makes it available. But it doesn't load it. It doesn't bring the functions that are inside of the package into the session. If you want to use something from this QTL package, for example, you first have to load it. So you say library QTL. And here, you don't have to put the brackets surrounding it to the double quotes. But you could put the double quotes here as well. And this will make the package available. So any function which is given to you by this package will now be available in R. It is not available until you load or until you do the library call. You can save an object in an R data format. So it's much smaller or it's smaller on your hard drive. Like if I have a big text file, which is two gigabytes big, then when I load it into R, R will have an internal representation which might be much smaller than the original text representation. So I can save that object in case I want to load it later. I can say save, then the name of the variable containing the object. And then I can say, save it to, for example, your dot R data or my dot R data, or I can just give it any name. I can save everything. So I can save the whole environment, right? So in my environment that I had here, I have x, y and z. So I can save one object. So I can say, save the x object and call this or put this in a file called x dot R data. And I could save everything using save dot image. And now save dot image will save x, y and z. If I would now clear my session, I think we had the clear session somewhere. So if I remove everything from the session, now nothing is loaded. If I now just type load, and I type load x dot R data. Now, if I do an LS, it now loaded back in x, y and z. And the values that we put in there are still in there. So it's an easier way to kind of, hey, if imagine that you're programming and someone calls you that your house is, well, not your house, but the house of your friend is on fire. So you have to leave now. Hey, then you can just save dot image, give it a file name and run out of the door. And then everything is saved. So if your computer will shut down, then you don't lose any work. If you want to quit, you can use like the button here to quit the R session. But if you are writing scripts, then you have to quit the session. But if it's called both, yeah, well, I just overwrote the file, right? So I wrote the same file twice. I once wrote x dot R data containing only x, and then I overwrote the file. So that, yeah, I could have given it a different name, should have given it a different name. Q with no will quit the R session and not save the workspace. This is one of these things that I always hammer on is never, ever save your default workspace. If you want to save your workspace or you want to save the whole environment, you use save dot image. If I would go, I don't know if you guys can see that, but when I click this button here, no, you don't see it will, it will put up one of these questions and it will save workspace image, question mark, and then it gives you three options. Yes, no, and cancel. If you if you click the yes button, then it will save a hidden file in your my documents folder called dot R data. The next time that you start are it will load everything which is in this hidden file, which can be really annoying because if I just, if in my session I have four gigabytes of data, and I click save workspace image and I click yes, then the next time that I start are it will take me half an hour for R to start up because it's loading in all these four gigabytes of data and only then is it available. So my advice to you is never save your workspace using the kind of question that it poses to you. Save workspace image, no, and that's why in the slide here, when I do queue, so when I call quit, I always say no, don't save the workspace. And this again comes in with the repeatability of research and the fact that by saving the workspace, stuff keeps floating around which you don't want to have floating around. Is there a way to make to check whether this has happened? Yes, if you open up your R window and you type LS, then it should show nothing. So it should be more or less empty, right? So if I would go to my R window, right, and I would do LS, now you see that I have stuff loaded. So this means that it saved this sneaky file. No, then it will just ask you. So if you just do queue like this, then it will pop up this window asking you if you want to save the workspace image, yes, no, or cancel. I don't know if cancel is actually an option. No, so you can only say yes or no, but never say yes. Always say no. So that's just my tip because it will hurt you in the long run because some variable X might be floating around from when you did a previous analysis and you don't want that. You want the whole analysis to be nothing more than what you put in your script. All right, so this is just a little bit about managing your session. Of course, like I told you in R, help is always available. So if you do question mark and then the name of a function, then it opens up the help file for this function. If I do question mark, if I just, if I don't know the function that I'm searching for, I can do double question mark and then a search term. So for example, if I want to open up the help file for the sec function, I just do question mark sec. If I want to open up the help file for the plus function, like I told you, every function in R has a help file, even plus, even just addition. But because plus is a special symbol, you then have to do the air quotes surrounding it so that it knows that you want to look at the help file for the plus function. And the help file for the plus function is really done because it just says this does addition, which is good. But it has an example. So if you don't know how addition works, there is an example there. If you want to search for something, like if you want to search for a function which deals with things like obesity, then you can do question mark, question mark, obesity, it will pop up a browser. And in the browser, you will see a list of things where the word obesity is mentioned. So you can search for obesity, but you can also search for other things. So if you want to do things like chi-square, then you do question mark, question mark, chi, and then it will search for chi-squares or everything that hits chi. All right. So the type system. And now it starts becoming interesting because there are different types in R. And these types of data are very important because they change the way that R looks at data. So of course, the most basic type that you can come up with is the logical type. So the logical type is true being coded by one and false and coded by zero. Or that's not entirely true because false is zero and true is defined as everything besides zero. So the logical values true and false, false being zero, true being everything else but zero. If you transform a true to a numerical value, then the false value has a numerical value of zero and the true will have a numerical value of one. But if I transform five to a logical, then five will be true. Numeric values are just numeric values. So that means it's five, it's 7.9 or 100.6. R has no notion of floating point numbers versus integers. A lot of programming languages make this distinction that something can be an integer, meaning one, two, three, four, five, six, seven, until infinity. And a floating point number like 2.3 or 7.9, R doesn't make that distinction. R just has a numerical value and a numerical value is any number. We have character values and character values are poorly named because character values can be single characters but can also be multiple characters. So the string one is a character type. Two is also a character type. The vector type is then a list of things. So I can use the c function, the combine function to combine things together into a list of elements. And this list of elements gets the type, the highest type. So this is the lowest type, intermediate type, and this is the highest type. And that is because a numeric value can be converted to a character, but a character cannot be converted to a numeric. So it has a kind of layered type system. Vectors are, there's three different types of vectors. You have numeric vectors, character vectors, and logical vectors. So I can have like a vector containing 1, 2, 5.36 and minus 2.4, or minus 2 and 4. And I can put this in something called v1. So here I define a variable v1. I use the combine function to combine these numbers together in a vector. I can create a character vector the same way, and I can create a logical vector exactly the same way. There's also a matrix types, which is a kind of tabular form. And here I am creating a matrix, which has the numbers 1, 2, 20 in there. It has five rows and four columns, and then I store it in a variable called y. Is this clear? Well, it doesn't matter if it's clear. There will be a short quiz in a short while anyway. So if you want to work with types, then there are some helpful functions, something like the length of an object. So if you ask for length of the name of a variable, it will tell you how many elements there are in. So if we would type, if we would define these three vectors, like for example, vector number two, and I would say length of v2, then it will tell you three. There's three elements in v2, like one, two and three. If I would ask for the length of v3, it will be five, because there's five logical units in this vector. The str is useful when you have more complex objects, because you can have a list with a vector with a matrix in there. So the str just gives you the structure of an object. And the class of an object will tell you what class or what type an object is. So if I say class of v2, then it will say character. If I ask for the class of v3, it will say logical. The names of an object in R, you can name things. So you can create a vector which has names, and then you can get the names of the object as well. So let me give you a small example of that. So we saw this v2 write, which is one, two and three. And now when I type v2, you see that it has three elements in there. But I can give it names as well. So I can say a1 equals one, a3 equals two, and b1 equals three. And now when I type v2, it will give names to this object. So if I now want to select this element from the vector, I can use v2, give me the second element, or I can say from v2, give me the element named b1. And then it will take the b1 element. So you can name anything. And this is really useful because often when you have measurements, measurements are done on individuals. And because of that, the individuals have names. So you often or you almost always want to use names for things to make them descriptive and to make your script more useful. This is especially true for here. When I say from v2 select the second element, it is better to select it by the name a3. And why is that? Well, if I would take v2 and I would add something to v2, for example, the object a with having a name called Hari or something like that. Right? Now when I say v2 element 2, the second element is now not the second element that it was. But if I would select v2, b1, I would still get the same thing. So it's good to use names because names don't change when you add or remove things from a vector, while the index like 1, 2, 3, 4 can change when you add or when you remove things. So just a tip, if you can use names, use names. How to know which brackets to use? Yeah, that's a very, very difficult question. So there's a whole slide on brackets and brackets is the thing that just it's going to be difficult. Square brackets are for selecting things from a list. Round brackets are calling functions. And the c is a function. So I say c1, 2, 3 to combine these three things together because c is a built-in function. v2 is not a built-in function. It is a list. And if I want to select something from a list, I use the square brackets. And you also have like the curly brackets and we will get to those. But there's a slide about it. So I will just continue. You can force things to be a certain type or you can ask if something is of a certain type. So if I want to know if a certain thing is a numerical value, let's go back to r, I can say is numeric v2. And it will say no, v2 is not numeric. If I want to ask if it is a character, then it will say yes, v2 is a character. So hey, you can and I can also force things to be or to go from one type to another. Does r put additions in a vector always on the first place or does it sort the element? No, I actually put it in the first place, right? I said here combine, Harry equals a and then v2. If I want to add something at the end of v2, I can say v2 is combine v2 and then put something after v2, which is called lala equals seven, right? If I do this, now it will take v2 and then add to the back the number seven with the name lala. However, if I now look at v2, then you see that the seven actually was upgraded. I put in the numeric seven, but because the other elements are not numeric, it upgrades the seven to be of a character type. And this is the thing that goes wrong most of the time in r. So the r type system is complex. It tries to be very smart and sometimes it's too smart for its own good. But depending on how I combine things, I can add it to the back or I can add it to the front. All right, so I can ask if something is of a certain type and I can actually force it to be of a certain type as well. So let's do this on v2. I can say as numeric v2 and then it will say, well, I introduced nA's, right? Because some things cannot be converted to numerics. The only one which could be converted to a numeric is this last one. So the value seven can be converted to seven, but a, one, two, and three cannot be converted to a numerical value. So those turn into nA's. So missing values, because I'm forcing it to be. So to create a vector or a matrix, if I want to create a vector, I can use the c function like we saw before. And then I can just name or throw in the objects that I want to combine. If I want to have a sequence, then I can also use the sec function, which creates a sequence from something to something by something. And I can repeat something an x number of times. So let's just give you a quick example of that. So I can, for example, say c123, right, which just creates a vector containing one, two, and three. I can do a sequence from one to a thousand, stepping by 50, right? So that's 151, 101, 151. And I can say, repeat the number a 20 times. And then it just repeats the number a 20 times. So that's how you can create vectors out of nothing. You can also create matrices. So the way to create matrices is using the matrix keyword. Then you say, you give it a vector. So these are the values that it is going to put into the matrix. And then you have to specify the number of rows and then the number of columns. You can also use the C bind function. So the C bind function is when you already have a matrix, and you want to add a column to the matrix. So I can say C bind an object to an object. So in this case, if I have a matrix, I can see bind to that matrix. So let's create a matrix, which has the numbers one to 20 in there. It has four rows, five columns, then it looks like this. And I can store this in variable, for example, a a. And now I can say C bind to a a a new column called Denny, and put in the values. And now I have to give four values, of course, because the column has four elements. So one, two, and three, and four. And now when you look at the matrix, it made a new column at the back called Denny, and it contains the values one, two, three, four. Of course, I could have bound it to the front as well, by doing like this. And now the Denny column that I just created will be on the front. There's also row bind function, which does the same thing. But now it works on rows. So you can add a row on the bottom or an add a row on the top. So that's the R bind function. All right, so there's slightly different ways to create a vector as well. There's this double point operator, which will, which is a shorthand for the sec function. And that is just go from one to four stepping by one. So it's it's sec one four. So it's sec one four comma one. But you can also write one, two, four. Here for the matrix, some examples on how to do that. Hey, you can see buying stuff together, or you can row bind vectors together to create a matrix as well. So when we type, or when when you type the name of a vector, right, you see that it puts these numbers in front. And when I type a matrix, you see that it automatically numbers the columns. So these are the indexes. So this is the first row. This is the first column like this. So the indexes are automatically assigned by our unless you give it names. So if I want to get stuff out of a vector, I always use the square brackets. If I want to, for example, select the fifth element from a vector, if I have a vector, which contains the letters a to I, and I want to select the fifth one, then I'm selecting the e. I can also from the vector, so I can, I can use a vector as an index to a vector. So in this case, I say from v, select the second to the fifth element, and then it will select for me a b c b c d and e. I can also from vector v select elements. So select, make a vector combine two to five. And then also give me the eighth number of the vector. So this will give me b c d and e. And it will also give me h. Is that clear? It's, it's just a way like you can use a numerical vector as the index to any vector to get the elements that you are interested in. But here you use the square brackets. Of course, here you use the round brackets for the C function. So here I create a vector. Why do we need to see here? Well, because we can, we need to specify that we also want element number eight. Two to five gives us this. And then if we want to have the eighth element as well, then we need to create a vector which contains two, three, four, five and eight. So that's why I'm using the C function here to combine the number eight with the vector two to five. And then I'm using this vector as the index to vector fee. It's a little bit swiveling. So you can swivel around and select. And of course, if I would put eight in front, so if I would say c eight, comma two to five, then it would give me the vector h a first age. No, that's not allowed. So v two to five, comma eight will give you an error. Because you're not doing anything with like two to five, comma eight is not meaningful. That's not a, so if I would just say v is letters and from letters, give me the first 10 or something. C for combine. Yeah, yeah. So hey, if I would take v, and I would take like the first letters, and then from V, I can select, for example, one to five. I can also select the other way around. I can select five to one, then it would select the other way around. I can select, for example, element one, four, seven and nine. And I also can selected the other way around. So I could also do something like this. So C combines and you can use any vector as an index to a vector. So you can use a numeric and a logical factor as so, but it will become more complex. Like, trust me, you can do a lot of weird things. But had just the basic understanding is that the square brackets here, you use to select from V. And the thing that we are selecting from V is, is can be specified using the index. And here we are using multi indexing. So we are saying combine two to five, and then eight. It's something that you just have to practice, right? It's something that will become very, very useful or very, very natural to you when you continue using R for, for some time. We can also do the same, we can index from a matrix as well. Same strategy applies. So from a matrix. And then now I within the square brackets, I have to give two coordinates, one coordinate for which rows I want, and then a coordinate for which column I want. So from matrix, if this is my matrix, when I say select the first to the third row from the first column, then I'm selecting these three numbers. So 0.7, 0.2 and 0.2. If I say from the fifth row, give me the third to the sixth column, then it will give me 0.42, 0.5, 3, 0.4. So it just selects. Isn't that the German flag? Kind of. The colors are more or less randomly chosen. And they, they, they change based on the system that I do. I can actually also select a single element like here. I can also select the whole column or a whole row by just leaving this empty. So if I say m square bracket open comma nine square bracket close, then it will know that, oh, I want to have the whole ninth column. Good. Is that clear? Then we will take a short break again. Let me think what did I actually come up with for animated GIFs. So let me.