R Programming 101 - Crash Course for beginners

Alejandro AO · Beginner ·🛠️ AI Tools & Apps ·3y ago

Key Takeaways

This video provides a comprehensive introduction to R programming, covering topics such as vectors, lists, data types, dataframes, and functions, with a focus on practical applications and examples.

Full Transcript

good morning everyone how's it going um today I'm going to be showing you how to use R and rstudio and this is going to be a very very introductory approach introductory approach to R and its capabilities okay we're mainly going to be going through some functions of our some data types and how to handle some basic data just to get your feet wet and like to get you started into what it means to do data analysis with r um if we have time maybe by the end we will be doing some data analysis with an actual data set but just think of this like kind of a crash course of all the functions and all the capabilities basic capabilities that you can have Within These programming languages language okay so there you go let's get right into it [Music] um all right so to start let's see what we got here um so R is a programming language they say programming language it works with um I mean on paper I think it is an object oriented programming language but don't really say that in public is I mean like the objects in R are pretty strange um um yeah I would probably consider it more of a functional programming language but there you go so let's get right into it there are several data types in R there are vectors there are um what else there are data frames there are matrices Etc but um I'm just going to show you for first of all the vectors how they work um so as you can as you probably know date R is made for data analysis and the basic um the most basic data unit that you have is the vector which is just a set of individual pieces of data of the same type okay so let's see how that looks like to create a variable uh wait let me just zoom right here there you go do you see everything I suppose there we go um all right so first of all I'm going to show you what it looks what this is this is our studio there is a web version for it you can use whichever you want I use the desktop version but yeah um you don't hesitate to use the other one um right here you have the console this is the r console you can run pretty much any um any um any are line that you want in here or you can have a script which is up here right here you have the environment which is where you will see all your data I mean yeah the data sets that you have imported the do variables Etc you will see them listed right here and right here you have the plot this is where you will see the plots that you have outputted or output or you you also have a viewer which is pretty useful if you're using a uh I don't know if you're running an applique a shiny app you can actually visualize it right here okay so it's kind of a very complete IDE for our I mean even though I really like code Studio and other IDs I mean for R I don't think there's a better thing than our studio so let's get right into it um to create a variable pretty much like in other languages you can use the equal sign but in r in the ACT actually the most correct way to do this is by using the arrow sign and you can think of it but just by saying telling to yourself that whatever whatever it is on the right is being assigned to the name to the variable name that's on the left okay I mean that's a good way to see it and here let's see we can create a um a vector with the function C which is short for create and right here you have like we have a vector 10 20 30. all right that's a vector of three elements and to run right right here we're inside the or inside the the script file but you can also run it in the console okay but to run the script file what you can do is just select it all and if you're in a Mac you would do command enter and if you're in a win in a Windows machine you would do Ctrl enter but let's see right here now I run it right here you see that I have my my Vector that's in my environment and you can see that it has three elements 10 20 and 30. now something interesting about this is that vectors Can Only Hold one data type so I cannot add right here hello which is a string because that would I mean it will run but do you see right here that this right here is a vector which is a vector of numbers which means that the elements inside it are numbers and since vectors can only take one data type if I add a string all of this will be coerced into Strings okay so let's see how that works I'll just enter right here and now you can see Hello has been added but 10 20 and 30 are no are not numbers anymore they're they're strings okay so that's how this one right here works so that's vectors there you go um secondly let's talk about lists lists are pretty much like vectors the only difference is that you can include several data types inside them and to create them you use you use the function list like this there you go and right here you can actually create you can actually add several data types you can add I mean this one right here will be a will be a number then we have another number then we have a list inside it yeah of course we can add a list inside the list and then let's add another Vector right here two three four there you go and let's see how that one works there we go so now you have a list of five elements and if we output it right here I'm going to run it in the console you can see that I have one two three four five six seven elements in my list one two three four five all right what oh yeah sure no sorry I have one two three four five elements in my list and inside the the fourth element you have another list which is this one right here okay there you go um what else do we what else can we do here all right let me show you the data types that we have right here okay um so as for data types you can have um different kind of values for a variable okay let's say for example The Logical logical one okay logical logical can be either true or false true is written like this and false is written like this and to check the type of a of a variable you can just surround it with the function class like that there you go and then if we run this one like here you can see that the class of this one is logical all right if we say the same about false that would be up sorry logical as well there you go right so that's for class um what else do we get here in one second there we go all right there we go so that's for clad that's that's the class of logical then you also have the class of one second yeah then you also have the class of integer as you can see here we were using numbers and right here we're using numbers as well but integers are not necessarily just numbers without if without um I mean in other languages something like this would be a float and something like this would be an integer okay but in r in order for it to be an integer an integer yeah sorry um you have to add a specifics L to it okay so let's say that if we do if we do class like this of 10 we will get the data type num numeric okay if we want the numeric data type to the an integer an integer what we would have to do is adder and L to it like this there you go so now that one's an integer um what else do we have we have um I mean floats are numeric just like that I mean if I run 10.5 and I ask for it and ask for the type it'll give me numeric it won't give me flow because flow time America just like that okay there it is numeric um what else do we got here all right unless you're a mathematician you might not use this but you also have um complex numbers which are um like constantly I mean just like in same in mathematics you just add an i suffix to it right so if I add let's say two plus three I oh I this one right here is going to evaluate to complex all right there you go complex um so that's it for data types I mean I can show you as well uh what I was showing you is the moment ago that for for the list right here um this one is a list of course and then the other one is a vector um yeah I mean it's a class vector and it's a character a character Vector because as we saw right here it's a vector of characters okay um yeah so there you go um those are the data types now let's see the most important thing um about this is the data frames all right um I'm going to create a data frame pretty quick right here a data frame a good way to define it is probably just to tell yourself that it's a collection of vectors okay vectors that are aligned like that so for example I'm going to I'm going to I'm just going to create a data frame off of several several vectors like this um all right so here we have the let me zoom in a little bit more here we have the patient ID the age diabetes status patient data all right there you go what are we doing right here so we're creating four vectors a patient ID so we're creating four ideas for it we have we are creating also four um variables for H diabetes also type uh type type 1 type 2 Etc this one's a character a vector this one's another character Vector um with the Thai header status and then please note that all of this have the same length you cannot create a data frame if all the vectors that are creating it are not the same length Okay so that is pretty important um so you have your patient data and right here is this one right here is the one that's going to be the data frame to create a data frame as well you just um initialize it with just as you did with a list and a and a vector use you initialize it with this function right here data.frame and then you pass in all the all the vectors that you want inside your data frame so I'm just going to run this right here now you see I have my four my four vectors and also I have my data set right here and it's a data frame indeed if you want to see it a good thing that you can do to see data frames is to run view and then you run your the name then you add the name of your data frame patience oops patient data something important to note I mean I don't love it but do you note that view the keyword I mean for the function of to visualize a data frame or a data set you have to start it with a with a with a cap all right so there you go um and then let's view it and there you have it that's the data frame a data frame you can think of it just like a table but like tables in r or something else so I mean it really just is like a table of information that you can manipulate okay um so there we have it now let's get back to our script and let's do some some stuff with that one um something that you would usually do with the data frame once you import it is to check the types of the columns that you have and to do that you can use you can use the function Str okay so Str and just let's just run patient data inside here and let's see what that one gives us all right so we have that our function has four columns patient ID age diabetes and status and it also gives us the type of functions for each the type of data for each of the columns which patient ID is numeric age is numeric diabetes is character and status is character okay uh all right that's interesting what else do we have right here I'm going to show you as well how you can download uh your own data I mean like right here we just created our data with some handwritten vectors but usually you would like get the data in a CSV file or from an API Etc so I'm going to show you how to open this from an from a CSV file um all right so there are two ways to do this one of them the easiest one is to just I mean first of all you have to have your you have to have your data set for this example I'm just going to be using the ever um ever popular Titanic data set and download it you can just come to kaggle uh Titanic slash data and just download the test one right here um it's a very simple one it has like just 11 columns and I don't know how many observations it has like several I mean enough to make an actual enough to make a good analysis a good exercise so let's just click right here and download there you have it and something that you can do to import it is that you can click right here import data set you click right here and then you choose it like I'm gonna choose it right here from here there you go then you give it to name I'm just going to call it Titanic and I mean you have several options right here that you can toggle but usually it's pretty much the same the most important one is um the separator which I don't see yeah there you have it sometimes CSV files are separated by semicolons instead of instead of Comas but this one is apparently separated by Comas so I'll just keep it like this right I mean you can see um an overview of how your date and data frame will look like because what what you're doing is just converting your CSV into a data frame then we click import and there you have it you have the Titanic data set with all your data in it there you go so now let's do some stuff with this one um there we go now let's do some stuff with this one um another important function that you will find is um one that is to check when oh oh so wait I forgot to mention the other way to down to import the data um as you as you can see right here if you come to history we can see the the function that was actually run by rstudio when we clicked on import data set and you can see that it's this one right here Red Dot CSV and this is pretty much the function that you're going to be using if you're working in a local project and you have your your data set a CSV file inside the same directory you can just do something like Titanic read.csv and then you just write the location to it remember that dot slash means current location and then you just I don't know you can go you can put it inside the data directory and just um Titanic Titanic test dot CSV or whichever is the name of your file that's how you import it right I just imported it with the button right here but this is the most um like professional I mean real way to import it um because it uses like relative paths um all right so let's let's continue with this um so we have the Str patient data to check the the vectors let's do the same thing with the with the Titanic Str Titanic there you go there you have it so we have um so we have the passenger ID which is an integer an integer we have the passenger class which is an integer as well we have their names which are characters sex character H number looks pretty complete looks pretty good uh something interesting that you can do is to see if you have any nans and to do that to do that you can for example see let's see if we have Nan to see if you have Nas you can use the function is Dot N A and then just run your data set right um Titanic for example and then we can even pass in a single column um so let's say that we want to see if we have any NES in passenger class for example and so we have false false false false false all right so this is probably not going to give you a lot of information um so what what you can do um there are several things that you can do right here um what I like to do is to um wrap it in a table table like this this is just going to give you like uh one like a table of all the false entries that you have so let's see so we only have false so there is no any ends in that in that column uh let's see if we run it like this oh in the entire data set apparently we do have 87 true uh any ends all right so we need to find them and see what we're doing I mean we're not going to be doing data cleaning in this video but um yeah um that's the way to see if you have any Nas or Nan's um what else we got right here I mean for a same column you can also use like functions like Max Min things like that right so for Titanic for example we're working with let's say let's say we're working with the H right here so instead of table and instead of n a what we're going to ask is for the maximum so we're going to see the maximum age of um uh the people of the passengers in the Titanic so again um I'm just going to do comment and for this one right here and apparently we have an N A apparently n a is one of the one of the columns where we have um where we have an ANS so to do to check this right here we can just wrap it in n a DOT omit and let's see right here um um our unexpected symbol any.ummit all right I forgot one of this there you go all right uh so it's apparently the oldest passenger was 76 years old um so there you go um Na omit to Omit an A's Max and or main or whatever like let's see who's the youngest one well a newborn newborn apparently and you can run this by column or you can run it on on the entire data set that's pretty convenient pretty useful now all right so that's all for basic Edie like exploring your data set let's I just write it right here exploring your data set there you go and now we're going to check sub setting and how it works um what is subsetting so sub setting basically means just like taking some parts of a certain data object that you have okay but not all of it in order to get just particular information from that part so let's say that you have a vector right here Vector one and I'm going to create a vector um that's going to be one two three four okay so now we have our vector of vector one right here you can see that it's numeric one two three four and what we're going to do is we're going to select some parts of it okay um all right so to select some parts of something be it a vector or a data set I'm just going to be focusing on vectors for now you run it with square braces okay and inside the square braces you just have to tell the positions that you want to be returned okay and the positions you you I mean the positions you select them with a vector as well so I have to create another Vector right here and say which positions I want to keep okay so I can say that I just want the first and second position in the vector number one so that's going to return the first two positions of the vector oh yeah something important um right here that I I don't know if I forgot to mention it before it's pretty bizarre and strange and I don't like it that much because I'm a software developer but R does not count from zero R Counts from one so this one right here would be position number one two three four whereas usually in any other programming language this would be positions zero one two and three so yeah keep that in mind if you're working with r so you have Vector one and we're going to find the position the we're going to subset the first two elements of the vector one and right here let's run this one and it's going to return one and two but why does it return one and two is it because I typed one and two right here no it's because one and two are in the first and second position right here if I change this to five and four or five and six let's say and I run this one right here this one is going to return five and six because those are the elements in the first and second position it has nothing to do with the actual numbers okay it's the position that matters so five and six so yeah we have the vector number one and we have the um we have the two the first two positions now there's another way to get all of this um remember that we're subsetting with with soft setting with with square braces so we can also use Vector number one and then we run the square braces right here and instead of passing a um the positions we can say exactly um we can pass in a vector that's the same length after as the original vector and we say just true true false false I mean like with logical operators right so if I pass in like right here a vector remember it's another and once again a vector I pass through true false true this one right here is going to return true for the first so it's going to return the first element true for the second so it's going to return the second element false for the third is going to so this one's not going to be returned and true for the for the fourth one so the outcome will be 5 6 and 4. let's see how that works there you go five six and four this is very important because this is like the basics for subsetting in actual data frames okay so once you understand how this works you will be able to subset in actual data frames because data frames after all are only vectors aligned one after the other okay so that's why this one right here is important um you can also run [Music] um uh comparison operator so you can say oops Vector one and let's say that any element that's below 4.5 that's lower than 4.5 so what do you think this one's going to return this one's actually going to return another Vector with false true false true true and that my friends if you see it's very very interesting because now you have a vector with logical operators that's exactly the same length as the original vector which means that you can pass it in right here right so let's now get actually get the elements that are that are lowered than 4.5 okay so this right here we can put it inside oh what so what's going on all right so this right here we can I mean right here you would usually take one of this a vector with the same length with logical operators but instead of that we're going to pass in right like this because this one right here returns a vector that's the same length of as Vector one but with logical operators so now we will return all the elements in Vector one that are lower than 4.5 so let's see how that works so we have three and four which are lower than 4.5 so that's a quick tip that you have in order to filter all the elements that are below 4.5 inside of vector 1. um so I'm going to put this right here subsetting there you go so that's for R that's for subsetting vectors in our um what else can I show you oh yeah how to select columns that's pretty important as well so um but that's not about vectors anymore all right one more thing let's suppose you have a vector two and it's defined as first element one well let's say yeah first equals one second equals two and Etc equals three okay these are the keys these are the values if you have worked with python before it I mean you I guess you can see it as a dictionary except that of course you cannot have different types of data inside it so I will just create this Vector number two and now to subset it or just to select a particular element inside it you can just call the key that you're that you want so you have vector number two and in and you just run etc for example and this one right here should return number three so let's see how that one works uh something went wrong um I think that this one has to be a string there you go yeah sorry so this one has to be a string so Vector number two etc etc has the Val and the key of Etc has the value of three so there we go um there we go um I'm just gonna show you pretty quick as well how to subset for lists and then we'll go we'll get into the into matrices and data frames which is the the juice of this um so what was the list that we had created it's called list right here okay so let's see what our list looks like um so we have our five elements and the fourth element has an inner list inside it so what we're going I'm going to show you um stop setting vectors right here I'm just going to create this Command right here and right here subsetting lists all right so we have our list which is list and and we're going to call we're going to call the first element right so let's see what do we get we get this but what is this let's see what is this class of this one which is a list okay so if we use only one bracket it will return a list even if the element that even if the first element is not a list the first element as you can see right here is just a number but if we use just one bright one bracket a single single brackets um this one's going to return a list with that element if we want the actual element we can add double brackets and this one right here will return only the element let's see what this one looks like class of this so this one right here is numeric okay so now there you go so that's subsetting lists um so yeah remember double brackets for the actual element and single brackets for a list with that element okay let's see how that works with element number four which was a list itself right because element number four right here is a list of one two three let's see how that looks like list let's see number four uh oops list there you go so we have this right here what is this a class of this one so apparently it's a list of course because at least with single brackets Returns the list but what is it if I use double brackets like I did just a moment ago well it's still a list because the element inside of this list so yeah I mean if we used only one bracket this one's going to return a list with one list inside it if you want to go even deeper right here but you would probably have to do is to select the first element for example and right here now this one should return the first element of the list that's in the fourth position let's see how that works yeah so the first element is one and it actually returns a list with that element I mean this I hope this is not getting too strange if I add another square brackets right here this one returns just the element Okay so this right here Returns the list of number four out of position number four and inside that list we already have another list so we're dealing with the same kind of rules that we were dealing with with it before another way of thinking about it is inner list and we give this one to list position number four and then inset in your list you can also be asking for the first position which Returns the list or double brackets which Returns the first element in that list okay and this right here is pretty much just the same as doing this right here all right so I hope that was clear for lists [Music] um now I'm going to show you how to do the same thing with matrices okay so to declare a matrix so to declare a Matrix Matrix you can do it like this I'm going to call it a Matrix you create with the function Matrix and then you just say the elements right here I'm just going to say one to nine and I'm going to say that the number of rows is three and let's see how that looks like so now we have our a which is a matrix and let's see what it looks like so we have our Matrix right here and just like as in a data frame and as I'm going to show you how it works in a data frame you can use square brackets to to select information inside it now the element on the left means the row and the element of on the right of the comma means the column okay so if I want the first element of the third of the I mean if I want the First Column and the element on the First Column and the third row that would be one point one comma seven this one's probably going to return seven let's see how it works yeah there you go so that seven um if you want the second element second row uh third column that's going to return eight probably there we go eight so that's how it works okay um now you can also select multiple columns you can do something like a um so that's why it's called sub setting right you just take a subset of of um of the bigger set uh so let's say we can we want to select this small square right here five eight six nine so what we would do right here is we would select the second row all the way to the third row and then for the columns we would select the second row all the way to the third one as well and this one right here is going to return the smaller one like that okay now this is pretty important uh because it kind of Echoes what you're going to be doing with data sets something also pretty interesting is that you can pass the actual numbers that you want in of the columns or the rows as well like right here I selected the range but this right here is actually translate this right this right here it translates to a vector with elements 2 to 3 which is two and three but I could also do something like this um two to three and a vector two and three right and it Returns the same thing and interesting thing about this is that I can just choose another one this one Returns the first one and the third one so right here we have this two three and eight nine two three and eight nine okay so that's subsetting from matrices um now let's get into Data frames which is um kind of the juice of of um R and because that's pretty much what you will be working with if you're using R for data analysis so data frames data frame state to frames what is the data frame a data frame as I mentioned before is the list of vectors data frames a data frame is a list of vectors which are the same length all of them and to select an element inside it sorry you also use square brackets just as you did before okay so just a moment ago we had imported uh Titanic data let's view that one let's just print it actually friend Titanic this one's going to well now it's probably a bit too big but here you have the entire data set for the Titanic okay and right now what we're going to be doing is that's the data set for the Titanic um we're going to select some columns okay let's see how that looks um so right now inside here we have our Titanic data set and we have that we have several columns right here let's say that we have to so we want to select the name column there are several ways of doing this you can use Titanic you I mean what you would usually see is you add the dollar sign and then you have you have to select the name of the column okay so we said that we were going to select the name column which is right this just type name there you have it now it returns all the names of all the passengers in a list okay um sorry um let's say if it's a list or a or a vector it's actually a vector right yeah it's a vector because a column is just a vector as I was telling you before so there you go um so that's that's for to select a a column but you can also do it like this um I think you can do it like this yeah it works as well uh with square brackets and you can also I don't remember if you can use name no I don't think this works no this one doesn't work just square brackets and the dollar sign that would do but something interesting as well is that you can just as with matrices you can say which element you want so let's say we want the third and the third element and the and the name of that element of that one which is in the third position as well so it works pretty much just like a just like a matrix in which if you say Titanic if you say Titanic three comma three this one's going to return the name in that position three comma 3. 3 comma three there you go and just as with matrices you can I like select you can select more than that or like like you can you can select a subset right so let's say that you want all the names for rows three to three to nine so this right here is going to return all the names for all the rows three to nine because remember the element on the left of the comma is the rows and the element on the right is the columns right so this one right here is going to check three to nine and then the third column which is name and now it's going to return all the names from here so that's how it works um what else do we have um oh I mean right now we're only selecting one column but you can also select more than one let's say that you want let's say that you want three two you want not only the name but you want also the you want also the sex so let's just say three to four so this one right here will actually return a data frame with all this with both of them and you can say um you can just create another variable for this one subset and now you can view that subset and let's see what it looks like so it's actually a data frame right here and you have the names and the text right here and you can you can also you you can I mean as us with matrices before you don't really have to select range this one right here just converts and translates to three and four but let's say that you don't want three and four let's say that you want three and five instead of six you want H so you use right right here three and five and this one right here is going to return the age instead of the of the sex right so yeah that's how this one right here works that's how you subset in in date frames um what else can I show you yeah all right I'm going to show you how to select pretty much every single element of a data frame um yeah like like this right so right here we were selecting three to nine and then column number three but what happens if you want all the columns well what have what you want to do is you want to leave the right side just empty and this right here is going to select all the columns right so let's see all columns if you run this one and then you view it remember view is with um um MySQL MySQL uppercase sorry uppercase uh all columns now let's see how that looks like so now you have all columns four rows three to nine uh that's how you subset data frames um what else can we do I mean you can do the same thing but on the other side you can select all the rows I'm just going to show you all rows Titanic and then just select all the rows so you just leave the left side empty and you just select let's say two of these let's say that we want um the name in the class right for all of the columns all of the rows I mean all of the observations so let's say that we want this and we won't uh so it's position two and three so I'd say two and three there you go and let's view all rows and there you have it you have all the rows for just columns b class and name there you go so that's for data frames um we're getting we're getting pretty far in I'm probably gonna end the video soon and let's just finish this with functions and [Music] foreign how do you create functions um to create functions you would use integrate functions the the way to create them you just type the name of the variable first let's say product and then you go equal function then you type in your R your um arguments inside here let's say a b and then you open curly braces and then you then you perform whatever you want to do with the arguments and then you return them to return them let's say that right here we're going to return [Music] oh by the way to return you need you need to wrap it in in parentheses so let's return a a times B so this one right here creates the product function and now if you want to use it you can just go product three and six oh have to run product as well there you go so three times six equals 18. so yeah that's how it works for functions what else can I show you oh yeah sometimes you might be able you might be needing to use anonymous functions like for example you have an L apply function that runs through all of the elements inside your columns inside your all of the rows all of your observations so what you can do is that you can call Titanic up Titanic um and then you say which h oh h does it work yeah age and then right here it'll apply what it does is that it runs through all of your although if your observations and then applies a function to them and saves the result of that function in place I mean if you have worked with other with other programming languages it's pretty much like mapping okay um so age right here and let's say that we want to multiply H by 2 okay I mean you can you can take a product that you can create a function that takes one argument and returns that argument times two or you can use an anonymous function okay I'm going to write this one here anonymous um Anonymous function um so you have Titanic H and what function are we going to apply let's say to add an anonymous function you just type in function then you just type in the name of your argument that you're going to use I'm just going to type in X I'm going to say x times 2. this is the ones that the thing that's going to be returned and this is the argument and this right here if we run it it's going to multiply the edge of every single one of our Titanic uh passengers times two so let's see how that one works um so here we have it uh Kelly James Kelly is 34.5 years old now if we run this one right here let's see what happened uh didn't work for some reason um oh right yeah I think it's yeah I think it doesn't work in place um Titanic H let's see if that one right here works yeah so now if I come right here yeah so it multiplied it by two so yeah this one doesn't work in place you have to actually this one Returns the list I mean the um the vector that with um with the results but you have to actually apply it to your to your to your column right so this right here won't do anything by itself it will just return the the results and then you have to apply the results to your column um but yeah um so right here we went through Anonymous functions and L apply which is pretty important if you want to update all of your elements of all of your observations in a certain column for R very very useful there you go what else do we have all right let's go a bit through loops so let's say that we have names and let's say that we have a vector called Mary um Joseph and Jesus why not so you can Loop through this Vector with the function four okay and this one takes in parenthesis and you take your name in names this one right here is the name that you're going to be using inside the loop and this one right here is the actual set of I mean it can be a vector I think you can iterate through lists as well but I'm not sure let's test that in a minute um so this right here and then we're going to print name let's see how that one works um didn't work for some reason um may be maybe um well it's not working right here um oh yeah sure I need parentheses right here there you go there you go so now we have Mary Joseph and Jesus which are printed right here because name is the one that we use right here we're just looping through the names um I mean it's not an array but it I mean you can think of it that way except for the fact that it all all of it has to be the same data type and then name you use it right here and you can do it whatever you do inside of here with your with your variable you also have a while loop like this you go count while count is less than five and we will just start with a count value of zero so while count is less than five we're going to count equal count plus one and let's just print count there we go so one two three four five so that's while how it works be careful not to get into an infinite Loop because you will break your computer and the universe will explode uh we don't want that to happen so yeah just be careful with that if at some point you do get into an infinite Loop right here you will have a red button called stop and you you just have to press it to save the universe good um what else do we have right here I think that's pretty much it for for [Music] um yeah I'm going to be sure I'm going to be uh I'm doing a continuation of this one where we will actually be working with a big data set like Titanic or Iris and I will show you how to do some basic data analysis with it like very very basic operations over a data frame but yeah um um it's going to be the it's it's the next video in this playlist so be sure to watch it and yeah see you around um well all right so I think that was pretty much all of it for r I hope it was useful I hope it was interesting and right now you should have all that's needed to actually start delving into data analysis with data frames that's what the next video is going to be about and what else yeah I mean sometimes this kind of things this kind of um knowledge it's kind of basic knowledge about a language is what ends up taking you the most time because you just jump in to do like very complicated things like I don't know like like you just don't you just want to jump in to do graphics and stuff like that and plots um but you will very soon be faced with the fact that you don't know how to subset um how to subset a data frame so you won't be able to actually do the plus that you want you will spend like hours and hours uh scrolling through stack Overflow and searching on Google to find the actual way to soft plot your data frame so now hopefully with this knowledge that you have right here you will be able to save all of that time and focus on what you want to do which is data analysis and plotting right and using ggplot uh yeah so in the next video we'll see ggplot um thank you so much for your attention and see you next time alright [Music] thank you [Music]

Original Description

This is an R programming tutorial for beginners who have never coded in R. We see how to learn r programming. You can find the code from the video here: https://gist.github.com/alejandro-ao/d984b31e0e47b98395242206a8e182eb R is a widely used open-source programming language for statistical computing and data analysis. R typically includes a command-line interface. R is accessible on popular operating systems like Windows, Linux, and macOS. The newest cutting-edge technology is the R programming language. Its development is presently being carried out by the R Development Core Team. It was created by Ross Ihaka and Robert Gentleman at the University of Auckland in New Zealand. An implementation of the S programming language is the R programming language. Additionally, it integrates with Scheme-inspired lexical scoping semantics. The project is also conceptualized in 1992; its initial version was delivered in 1995; and its stable beta version was released in 2000. R is simpler to code in and understand since it shares many syntactical similarities with other widely used languages. Any of the frequently used IDEs, such as R Studio, Rattle, Tinn-R, etc., can be used to write R programs. ------------------------------------------------------------------------------------------------ ⏰ Timestamps 0:00 Intro 3:52 Vectors 6:15 Lists 7:33 Data types 11:25 Dataframes 14:35 The structure of a Dataframe 15:28 Importing your data 19:55 Checking for NaNs 21:06 Checking columns 23:20 Subsetting vectors 32:08 Subsetting lists 36:08 Subsetting matrices 39:49 Subsetting dataframes 47:35 Functions and lapply 52:45 Loops 55:31 Outro
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Alejandro AO · Alejandro AO · 3 of 60

1 Linear Regression in R - Full Project for Beginners
Linear Regression in R - Full Project for Beginners
Alejandro AO
2 Configure Webpack 5 in Wordpress (2025) with Typescript and SASS
Configure Webpack 5 in Wordpress (2025) with Typescript and SASS
Alejandro AO
R Programming 101 - Crash Course for beginners
R Programming 101 - Crash Course for beginners
Alejandro AO
4 Convert HTML template to WordPress Theme (2025) - Full Course
Convert HTML template to WordPress Theme (2025) - Full Course
Alejandro AO
5 Javascript Interactive Map with Leaflet EASY (with Marker Clusters & Popups)
Javascript Interactive Map with Leaflet EASY (with Marker Clusters & Popups)
Alejandro AO
6 Vanilla JS Project: Multi Step form in HTML, CSS & OOP Javascript
Vanilla JS Project: Multi Step form in HTML, CSS & OOP Javascript
Alejandro AO
7 How to do AJAX in WordPress correctly (2025)
How to do AJAX in WordPress correctly (2025)
Alejandro AO
8 React Leaflet Tutorial for Beginners (2025)
React Leaflet Tutorial for Beginners (2025)
Alejandro AO
9 Linear Regression in Python - Full Project for Beginners
Linear Regression in Python - Full Project for Beginners
Alejandro AO
10 Logistic Regression Project: Cancer Prediction with Python
Logistic Regression Project: Cancer Prediction with Python
Alejandro AO
11 Display Equations in ChatGPT
Display Equations in ChatGPT
Alejandro AO
12 Create a Chrome Extension (Manifest V3) for ChatGPT
Create a Chrome Extension (Manifest V3) for ChatGPT
Alejandro AO
13 Full-Stack Project | ChatGPT API, React, Node.js, Express
Full-Stack Project | ChatGPT API, React, Node.js, Express
Alejandro AO
14 Streamlit Python Course: Build a Machine Learning App to Predict Cancer
Streamlit Python Course: Build a Machine Learning App to Predict Cancer
Alejandro AO
15 Langchain PDF App (GUI) | Create a ChatGPT For Your PDF in Python
Langchain PDF App (GUI) | Create a ChatGPT For Your PDF in Python
Alejandro AO
16 LangChain Memory Tutorial | Building a ChatGPT Clone in Python
LangChain Memory Tutorial | Building a ChatGPT Clone in Python
Alejandro AO
17 Chat with a CSV | LangChain Agents Tutorial (Beginners)
Chat with a CSV | LangChain Agents Tutorial (Beginners)
Alejandro AO
18 Create a ChatGPT clone using Streamlit and LangChain
Create a ChatGPT clone using Streamlit and LangChain
Alejandro AO
19 Chat with Multiple PDFs | LangChain App Tutorial in Python (Free LLMs and Embeddings)
Chat with Multiple PDFs | LangChain App Tutorial in Python (Free LLMs and Embeddings)
Alejandro AO
20 Full Python Environment Setup for AI (or other) Apps + Virtual Environments
Full Python Environment Setup for AI (or other) Apps + Virtual Environments
Alejandro AO
21 Langchain + Qdrant Cloud | Pinecone FREE Alternative (20GB) | Tutorial
Langchain + Qdrant Cloud | Pinecone FREE Alternative (20GB) | Tutorial
Alejandro AO
22 LangChain Version 0.1 Explained | New Features & Changes
LangChain Version 0.1 Explained | New Features & Changes
Alejandro AO
23 Create a RAG Chain using LangChain 0.1 (New version)
Create a RAG Chain using LangChain 0.1 (New version)
Alejandro AO
24 Tutorial | Chat with any Website using Python and Langchain (LATEST VERSION)
Tutorial | Chat with any Website using Python and Langchain (LATEST VERSION)
Alejandro AO
25 Deploy Your AI Streamlit App for FREE | Step-by-Step (Heroku Alternative)
Deploy Your AI Streamlit App for FREE | Step-by-Step (Heroku Alternative)
Alejandro AO
26 What is Google's Gemini 1.5 Pro | 10 Million Token Window
What is Google's Gemini 1.5 Pro | 10 Million Token Window
Alejandro AO
27 Chat with MySQL Database with Python | LangChain Tutorial
Chat with MySQL Database with Python | LangChain Tutorial
Alejandro AO
28 Stream LLMs with LangChain + Streamlit | Tutorial
Stream LLMs with LangChain + Streamlit | Tutorial
Alejandro AO
29 Chat with MySQL Database using GPT-4 and Mistral AI | Python GUI App
Chat with MySQL Database using GPT-4 and Mistral AI | Python GUI App
Alejandro AO
30 #1 Harrison Chase: LangChain and The Future of LLM Applications | Alejandro AO
#1 Harrison Chase: LangChain and The Future of LLM Applications | Alejandro AO
Alejandro AO
31 CrewAI Step-by-Step | Complete Course for Beginners
CrewAI Step-by-Step | Complete Course for Beginners
Alejandro AO
32 Python: Automating a Marketing Team with AI Agents | Planning and Implementing CrewAI
Python: Automating a Marketing Team with AI Agents | Planning and Implementing CrewAI
Alejandro AO
33 Build a Web App (GUI) for your CrewAI Automation (Easy with Python)
Build a Web App (GUI) for your CrewAI Automation (Easy with Python)
Alejandro AO
34 Early days of RAG and LlamaIndex - Jerry Liu
Early days of RAG and LlamaIndex - Jerry Liu
Alejandro AO
35 LlamaParse: Convert PDF (with tables) to Markdown
LlamaParse: Convert PDF (with tables) to Markdown
Alejandro AO
36 #2 Jerry Liu - What is LlamaIndex, Agents & Advice for AI Engineers
#2 Jerry Liu - What is LlamaIndex, Agents & Advice for AI Engineers
Alejandro AO
37 CrewAI + Exa: Generate a Newsletter with Research Agents (Part 1)
CrewAI + Exa: Generate a Newsletter with Research Agents (Part 1)
Alejandro AO
38 #3 Joe Moura | Multi Agent Systems and CrewAI
#3 Joe Moura | Multi Agent Systems and CrewAI
Alejandro AO
39 Python: Create a ReAct Agent from Scratch
Python: Create a ReAct Agent from Scratch
Alejandro AO
40 New Groq Models: Best for Function-Calling Agents
New Groq Models: Best for Function-Calling Agents
Alejandro AO
41 Introduction to LlamaIndex with Python (2025)
Introduction to LlamaIndex with Python (2025)
Alejandro AO
42 LlamaIndex: How to use LLMs
LlamaIndex: How to use LLMs
Alejandro AO
43 LlamaIndex: How to Get Structured Data from LLMs
LlamaIndex: How to Get Structured Data from LLMs
Alejandro AO
44 Multimodal RAG: Chat with PDFs (Images & Tables) [2025]
Multimodal RAG: Chat with PDFs (Images & Tables) [2025]
Alejandro AO
45 Advanced RAG with LlamaIndex - Metadata Extraction [2025]
Advanced RAG with LlamaIndex - Metadata Extraction [2025]
Alejandro AO
46 Learn MCP Servers with Python (EASY)
Learn MCP Servers with Python (EASY)
Alejandro AO
47 Create MCP Clients in JavaScript - Tutorial
Create MCP Clients in JavaScript - Tutorial
Alejandro AO
48 Create an MCP Client in Python - FastAPI Tutorial
Create an MCP Client in Python - FastAPI Tutorial
Alejandro AO
49 How to Build an MCP Client GUI with Streamlit and FastAPI
How to Build an MCP Client GUI with Streamlit and FastAPI
Alejandro AO
50 Vibe Coding For Engineers (make it ACTUALLY work)
Vibe Coding For Engineers (make it ACTUALLY work)
Alejandro AO
51 LlamaExtract Tutorial: Convert PDF & Images into JSON
LlamaExtract Tutorial: Convert PDF & Images into JSON
Alejandro AO
52 Local MCP Servers for Cursor (Step by step)
Local MCP Servers for Cursor (Step by step)
Alejandro AO
53 Anthropic: How to Build Multi Agent Systems
Anthropic: How to Build Multi Agent Systems
Alejandro AO
54 Deploy Remote MCP Servers in Python (Step by Step)
Deploy Remote MCP Servers in Python (Step by Step)
Alejandro AO
55 GPT-5 for Developers: API Changes, Pricing, Model Router & Security
GPT-5 for Developers: API Changes, Pricing, Model Router & Security
Alejandro AO
56 Tutorial: Auth for Remote MCP Servers (Step by Step) | OAuth 2.1 with ScaleKit
Tutorial: Auth for Remote MCP Servers (Step by Step) | OAuth 2.1 with ScaleKit
Alejandro AO
57 Generate UI Tests with TestSprite MCP Server + TRAE
Generate UI Tests with TestSprite MCP Server + TRAE
Alejandro AO
58 #4 Allan Guo | 19-yo YC Founder - Willow Voice
#4 Allan Guo | 19-yo YC Founder - Willow Voice
Alejandro AO
59 RAG Project: Build an AI Onboarding Chatbot with Streamlit, LangChain, and ChromaDB
RAG Project: Build an AI Onboarding Chatbot with Streamlit, LangChain, and ChromaDB
Alejandro AO
60 MCP Security | Malicious MCP Servers (Protect Yourself)
MCP Security | Malicious MCP Servers (Protect Yourself)
Alejandro AO

This video teaches the basics of R programming, including data types, dataframes, and functions, and provides a foundation for further learning in data science and statistical analysis. The video is designed for beginners and covers both theoretical and practical aspects of R programming. By the end of the video, viewers will be able to write their own R programs and analyze data using R.

Key Takeaways
  1. Install R and an IDE such as R Studio
  2. Create and manipulate vectors and lists
  3. Understand and work with data types and dataframes
  4. Import and subset data
  5. Write and apply functions in R
  6. Use loops and conditional statements in R
💡 R programming is a powerful tool for data analysis and statistical computing, and its simplicity and flexibility make it an ideal language for beginners and experienced programmers alike.

Related AI Lessons

Chapters (16)

Intro
3:52 Vectors
6:15 Lists
7:33 Data types
11:25 Dataframes
14:35 The structure of a Dataframe
15:28 Importing your data
19:55 Checking for NaNs
21:06 Checking columns
23:20 Subsetting vectors
32:08 Subsetting lists
36:08 Subsetting matrices
39:49 Subsetting dataframes
47:35 Functions and lapply
52:45 Loops
55:31 Outro
Up next
I Asked ChatGPT to Apply to 500 Jobs (8 Interviews in 48 Hours)
Sabrina Ramonov 🍄
Watch →