R Programming Tutorial in 2018 Variables Operators and Data Frame R Tutorial Intellipaat

Show video

Hey. Guys welcome. To yet another interesting. Session, by in telepath and today, we are going to learn about our programming, so. We'll start off by understanding, what. Exactly is our language, and then, we'll learn about variables, in our following. Which we learn about different types of operators, and finally. We'll, walk with data types in R so. Let's get started, so what are, our. Language. Developed. By statisticians, for. Statisticians. And thus. If you want to perform any sort of statistical, analysis, or is. A go to language R. Is also a great visualization, to will R provides. Visualization. Packages, such as ggplot2, DG. Us and plotly, to, create stunning visualizations. And. The best part about RS, is a, Turing complete language that. Is it, can perform any task which, a touring machine can are truly. Is an awesome, language, so, let's go ahead and install our in a system, so. I'll just type out download R over here. I click, on the first link. So, this is the site tan dot our project, Obagi and this, is the latest version of our three, point five point one and since, I'm using a Windows system download. To Windows, right. Click, download it are now. After installing are you would also require, an IDE, to work with our one. Such IDE is our studio so we'll, head back and also download our food you know. Open, a new tab and I'll. Die. Download. Our studio, I cannot, look on the first link. I would, require the free version and, I. Got in since I'm using the Windows system I'll download it for Windows. Right, round, has started now we have installed, our and we have installed our studio, now. Well go ahead and understand, what our variables in our simply. Put a variable, is a temporary, storage space over. Here this, box is a temporary storage space which, can hold only one object at a time we. Have an apple with ice and we place it inside this, box after. Some time we, decide to remove this apple and replace. It with a strawberry, again. After, some time replace. The strawberry, with a tomato because. Tomatoes are the best aren't they and this. Is pretty much how variables, for these, whole temporary, values, which can be changed again and, again, now. Let's go ahead and implement, variables. In our so, this is our studio guys this is how our studio looks like we'll. Be implementing, variables, over here. So, I'll just see e. Equals. Let. Me actually change and, actually name. The variable, to be true. New. Stores. Apple. Let. Me then the value of food right. The fruit is Apple now now. Let me change the value of the food, to. Strawberry. Now, if I print. The. Value strawberry. Let. Me change it again. Now, I, feel. Like eating a banana. Right. So, we see that the value has been changed to banana so. This is how variables, function, we can keep changing the values again and again. So, that was a simple example with variables, now.

Let's Learn about different types of operators. Broadly. Speaking we, have arithmetic, operators, assignment. Operators, relational, operators, and logical, operators, now, let's implement all of these in R so, we are back to our studio, now. We'll, start off with arithmetic operators. So. Arithmetic, operators, provide. Us with simple arithmetic functions, so. This I want to add PI, plus, 6, which. Is 11 obviously, now. If I subtract, and. -. Five I'll. Get five that. Was addition, and subtraction, now let me divide ten with respect to five the. Answer is obviously two now. If I want the remainder, then. I will use the modulo, operator so. Tan portion. Percent symbol pi. Right. The modulo, of the remainder for this is zero. Now. We had, seen the plus operator -. Division, and modulo operator, these. Were the basic arithmetic operators. So. You can actually assign, this values, to variables and. Work. With arithmetic operations, of the variables, as well what, I'll do is I'll just say. Num. 1e. Will stand, and, I'll, take the second number to be num2 and I'll get the value by. Now. Oh here, I'll type num1 plus. Num2. And this. Is our result which is 10 plus y equals 15, let. Me subtract, these num1. -. Num2 which. Is 10 minus 5, is, nothing but 5, alright, now, it's time to multiply. Num1. Cross. Num. To, 10, cross. Is obviously, 50, now. Let me actually take the power of this so numb 1 piece. To, the power. Number, two is 10 raised to the power 5 is nothing but 10 power 5. Right. So, these were the basic arithmetic operations. Now. Let's go ahead and see some assignment, operators. Assignment. Operators, are pretty simple we just use them to assign the values, so. Let us say. Game. Is a variable, and this. Is the operator, here this is the assignment operator, now. Right. And this is how I'm assigning the value. Teams on. Now. I, can, assign, a, V, as well being. Equal. To on or, I can. Directly, use the value and then. Give, it to the variable. Came. Right it's the same thing. This. Was. The assignment, operator now. Let's go ahead and check out some relational. Operators, the. Relational, operators are greater than less than greater than equal to less than equal to now. Let me compare num1 and num2, so. Number, on s 10 and num2. Was, 5 so. Let me check if num 1 is greater than num2 1 odd number. 1 greater. Than num2. It. Gives me the value true that as num1 which is 10 is obviously greater than 5, now. Let me do the reverse let me see if num 1 is less than num2, or not, it. Is actually false because 10 is, obviously, not less than pi. Now, let me see if num 1 is equal. To num - so, nom bond double. Equal to num. - and, I see that number is obviously not equal to num -, right. Now there is also an not, equal, to operator number, is. Not. Equal. To num2. Which, is again true, these. Were the relational, operators, now. Well it's like some logical, operators.

So. Logical. Are simply. And and or. So. Let me give the value of all, as a logic, 1. As. The. Value. Proven. It. And. Logic. 2 has, a, value. All Internet. So, logic, one and. Logic. Do. Right, that is true and false, so. True and false is obviously, false, now. Let, me see logic one and logic. One which is true and true, is, again true. Let. Me check logic, two with logic, two. This, falls and falls so. Falls and falls of, this leaves me falls so. And operator. Gives me the true value, only, when good, the operands. Are true otherwise it, will just give me the false value, now. Let's check out the or operator. So. Or we'll, just keep the pipe operator. So. Logic - and logic - that is false or false, which, is obviously false, now. Let's check true or true. Which, is obviously true now. Let's check true, with respect to false true or false. Which. Gives us true so. This is how our operator. Works so, these moves some examples, of logical, operators. Now. Let's, head back and understand, what, exactly are. Data. Types in our. The, most basic data type in R is a vector, it's a homogeneous, Dooney dimensional, object, so, what do I mean by homogenous, well, all of its elements will be of same type like. Over here we, have a collection, of boots linearly, arranged, now, let's implement this in our. Right. So. I'll read, back. To and I'll name it as bird and, I'll. Give it some values, so the first element is. Parrot. This, is my favorite booth the. Next element, is. Lejeune. And third. Element, is the, Mighty Eagle. So. We have this vector hood. Which, comprises, of the elements. Which are padded region. And eagle now. When. I said that a, vector, is always homogeneous. This is what I mind so all of these three elements are, of, character, type let, me check the class of this so I will say plus. Oh good. Now. This is a character, vector similarly, let me create a numeric vector. The. Numbers, would, be my numeric went to and I'll. Assign, the values, 1. 2 9 in this numeric vector. When, I print this, so. This is the numeric factor now let me check the class. Plus of. Numbers. Right. So, this is the integer, vector, or the numeric web down, now. Let. Me create a logical, vector, so LG. I'll. Name, it to be. Logic. Hundred. And let, me assign some value so as it true-true. All. Falls. And. Falls. So, let me bring logic hundred, now. So, this as the logical vector, it's comprised, of these five elements which are true true false. False and, false let. Me check the class. This. Is class of. Logic. Hundred, which. Tells me that this is a logical, vector. Right. So. Way. Down with America to character, vector and logical, vector. Now. Let's. See what, happens, if we makes one sort of data type with another data type so. Let me name this as, jumble. And. I'll. Say well. 34. And let, me get the value of rodeo. Now. Let's see what happens, tonight. Prentiss. What. We see is this, logical, value, has. Turned. Into its numeric, value which is one that, s numeric. Value stick precedence. Or the logical, values, and hence. We have the same class overall, let. Me take the class again this. Will be class, of jumble. Which. Tells me that is a numeric vector right. Now, again. Let me create another. Vector. Ooh you. Leave. It as jumbled, - and let. Me give some value so. Let, me say nirvana which is my favorite rock band let. Me give a logical value you. True, and let me assign numeric value which is hundred now, let's see what happens. So I'll type jumble to you. Right. So this gives me a character. Vector, that is nirvana. Dot. S character, vector, has the greatest presidents. Oh other vectors, so. First comes character, then comes numeric, then comes logical, so this is the order of precedence. Right. So. This. Horse. So, this was vector in are now. We'll head, back and. Understand. What exactly is a list, so. A list is a heterogeneous, collection, of, elements that, as the, elements, do not have to be of same type and each, element retains. Its own identity like. Oh here you, have a heterogeneous collection, comprising. Of a bird an apple, in a book, again.

We'll Go ahead and implement list in R so. Let me create a new list and let, me name the stupi. Basket. So. This. Is how we create less, and. I'll. Give a character value who you so, I'll say son, and. I'll give a numeric value at. 8500. I'll, give a logical value which, is false. Now. Let me bring, this, list, so. This is how Alice looks like so, we see that all of the identities, of the individual, elements are retained, so, Sam which is a character, stays as a character. 500. Which is numbered, steel as a number, false. Which, is of logical, type stays, of the logical type. Right. Now. What. We'll do is we'll, create two separate vectors and, store them in a list let's see what happens, so, let, me create. Crew, vecto. And let. Me add some hoops in it. Host fruit, would be Apple, next. Will be here. Banana. And the third fruit would be. Let. Us see grapes. So. We have, fruits. Of you then, we'll also add the corresponding cost. So, in create a new vector named, as cause and give the values so. The values would be Apple, cause let us say hundred rupees, a banana, cause around. Thirty. Rupees and, grapes cost around fifty rupees, right, so we have a two vectors now let's, pass both of these it, will list again. We'll name the list we basket. All right, list. So. One. So, the forest. Vector, was food the next vector was cost. So, this is what we see over here so the first element of, the list comprises. Of, a vector similarly. The, next element, of the second element of the list comprised. Of a gano vector which is the cost, now. What, if we want to access individual. Elements of, the list how can we do that that, is actually quite simple, so. Let us see i want to access just, the fruits so. What i'll do is i'll type, out. Basket. And. I'll. Say 1 so. This gives me the first element, of the list which. Is a vector of fruits. Again. Similarly, I will say basket, of 2 which gives me the second, element of the list which. Is the cost for all of the fruits and, what if I wanted, to access, the second, element, from. The first element for that as this. Banana, from, over here, so. This is how we can do, so. I'll. Type, our basket. And from. Inside, the basket. Paris. From inside the first element, I am accessing, the inner element, but. Just to right. Now. Let me access the third element similarly. And again, similarly let me access the first element. Right. So this is how we can access individual. Elements from, the list. Yes, with, the concept of less, next. In line is a matrix so, metric is a homogeneous, collection, of elements in, two-dimensional, space so. Here all, of the bullets are arranged. In rows in columns so, now let, me go ahead and implement a matrix in R so. For the eyes let me actually create a vector again. I'll use, the numbers vector, so. This conscious of elements, from 1 to 9, now. This, is how we can create a matrix so we'll use the matrix function and.

Given. The data. Which. Takes. In the vector numbers, and. Consider. Nine numbers, I would want three rows and three columns so. I'll steal Andrew. Equals. Three and and. Call, as also. Three. Let, me print this now. So, I have my matrix which, consists of three rows and three columns and, this was the vector now, we see that these numbers are. Arranged, with respect to the column RS, one two three four five six and seven eight nine now, what, if I wanted, to arrange the numbers, with respect, to the road so, this is how we can do all. I have to do is use T value attribute, and assign. It to be true right. So, what we see is the numbers are aligned, with respect to, row so, one two three four five six and seven eight nine right. So this is how we can implement a matrix. Now. It's time to learn the final data structure, which, is a data frame so. Patita, frame is a heterogeneous, collection, of, elements in two-dimensional, space so. Over here the, first column comprises. Of roots second. Column comprises, of goods and the third column comprises. Of cars so. Time to head back to our and implement, a data frame now I'll actually create a student data frame over here so. Let. Me type. Student. Name, and. I'll. Add. Three elements, to it the first student. As, Sam. The. Second, student, as Lisa. And. Each. Student. Bob. So. We have the names of the students now let me also add. Marks. To the students, so. Student, marks. Let, me assign marks, to them so. Sam does not study at all and that is why he's gorgeous ten marks, lisa. Is a topper who scored 99 and bob, is an average student scored 55. Right. Now we'll, give them the Greeks that is we'll check if they pass the test an art so. I'll create, a new vector and emitter student, powers. Since, Sam has gorgeous ten marks he has obviously failed, in the exam, Lisa. Being the topper has obviously passed bob. Has just managed, to pass the exam with 55 marks. Right, now. Let's. Create a data film with these three vectors. So. I'll create a data frame with the name, student. Details. And, I'll use the, data. Frame function, here so. I'll give student. Email, first argument. Student. Marks at the second argument. And student. Pass as a tow document. Let, me print us. Right. We. Can actually view data frames so I'll say view of stood. And. Details. So, this is. A DITA frame student, details, which comprises of a name, of the student the marks of the student and whether, the student has passed the exam or not and, what we see is this is a heterogeneous data, structure, and comprised. Of three columns the first column, is, of character type the second column is of numeric type and the third column is of logical, type right.

So These were all of the data types in R and this. Also brings, us to the end of this video, so. Let's have a brief recap so, we started off by understanding what exactly is our language. Then, we understood what the variables, in our boiling, which we implemented operators. In R and finally, we looked at different types of data structures, in our and implemented, all of them thank. You for watching the video and if, you're really interested in, doing an end to end our course, then, you can join in telepaths, our training course which, has different topics, such as our packages, data visualization. The Interbrand Ling and machine learning, thank. You very much for watching the video.

2018-07-10

Show video