R Programming Tutorial in 2018: Variables, Operators and Data Frame | R Tutorial | Intellipaat Show Video

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 22:19

Show Video

How to access individual columns from the “student_details” data-frame?

Hi Vikrant. You can access it by using student[‘student_name’]. i.e giving the name of the column inside []. To get more knowledge on R Programming do check out our other videos. https://goo.gl/Szm1Li :)

Very very nice session

Glad you liked it Kirti. Do check our other videos on R Programming for more knowledge... https://goo.gl/Szm1Li

Hey.. You can use ‘\$’ symbol. i.e student_details\$student_name.

Hi.. Can a list contain another list inside it?

The color of R studio is too dark. Can i change it?

Hi Radhika, thanks for watching the video. Of course you can change it. Go to Tools ->Global Options ->Appearance. Do watch our complete R Programming tutorial for more knowledge:- https://goo.gl/Szm1Li

Hi, how can I give column names to the matrix created in the video?

Hey Poorva, you can store the matrix in a variable and then use colnames() function. matrix1

Hi Neha, Yes you can. Check this example and implement in rstudio….. student

yes, a list can contain heterogeneous elements.

Got a question on R Programming? Do write it in the comment and you will get a response immediately by our expert. For R Programming training & certification, call us at US: 1800-216-8930 (Toll Free) or India: +917022374614. You can also write us at sales@intellipaat.com

I'm a mechanical engineer and planning to make career in data science. So which is better for me to go with Data Science….. R or Python?

Hi Peehu, glad you liked the video. Well, both are equally good, depends what language you are more comfortable with. If you have a basic knowledge about programming you can go with Python or else R would be better for you. You can talk to our course advisers for career related guidance on +917022374614. Do watch our complete data science with r playlist to learn more.... https://goo.gl/Szm1Li

WOW , This is the best Tutorial have seen in a long time

Hi Maahi, glad you liked the video. Do watch our complete data science with r playlist to learn more.... https://goo.gl/Szm1Li

Epic work. Nice and clear explanation

Best tutorial so far. Great work. Hope this continues for the entire session.

Hi Himanshu, glad you liked the video. Do check our complete data science with r playlist to learn more.... https://goo.gl/Szm1Li

Hi Mohit, glad you liked the video. Do check our complete data science with r playlist to learn more.... https://goo.gl/Szm1Li

Nice!Learning should have been like this.

Glad you liked the video. Do subscribe to Intellipaat channel to learn more: https://goo.gl/hhsGWb

Thanks for explaining simple.

Thanks for clarifying the things..Best wishes for this series...Just go like this.

Great Post , Thanks for sharing....

This Video is simply Amazing,straightforward, Concise and Clear all wrapped in one Video!!!......Truly Great Work

GOOD INTRODUCTION.

Thanks for such a nice explanation. Amazing work!

Great tutorial. Thanks!

Thank you very much for your tutorial.

Thank you so much for your video. It's very helpful.

Wow. I enjoyed this video.

wonderful

Thanks..!! nice video which helps for first step.

Very nice and concise. Video description is also very helpful. Thanks!

Thanks for the guide, your tutorial was easy to follow and informative!

this was very helpful.

This is amazing and exactly what I needed. Thank you so much!

Awesome tutorial - loved it!

very nice explained video

Glad you liked the video. Please subscribe to Intellipaat channel to learn more: https://goo.gl/hhsGWb

nice video, quite useful to understand

Your style and method are excellent. I was able to follow you with ease and learn a lot. I will look for more of your videos!!

Glad you liked the video. Please subscribe to Intellipaat channel to get updated on the latest technologies & learn more: https://goo.gl/hhsGWb