Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,080 --> 00:00:04,380
Hello everyone and welcome to the lecture on variables.
2
00:00:04,380 --> 00:00:09,990
This lecture we're going to go over some conventions on naming variables and how to assign the variables
3
00:00:10,080 --> 00:00:11,040
in R.
4
00:00:11,220 --> 00:00:13,710
Let's go ahead and jump to our studio.
5
00:00:13,710 --> 00:00:19,260
All right so here we are our studio and what I'm going to show you is just a couple of things that we're
6
00:00:19,260 --> 00:00:23,610
going to be learning as we begin our journey on learning the our programming language.
7
00:00:23,610 --> 00:00:27,030
And the first one we want to know is what actually comments or code.
8
00:00:27,270 --> 00:00:32,130
So what if you just want to leave yourself some notes either in your script or in the console.
9
00:00:32,130 --> 00:00:37,970
You can do is use a hash tag and this is similar to the Python programming language.
10
00:00:38,160 --> 00:00:44,070
And then whatever you write after the hash tag such as this is a comments.
11
00:00:44,130 --> 00:00:50,150
If you end up running this you'll notice that nothing comes out.
12
00:00:50,190 --> 00:00:53,040
So let's go ahead and show that in the console.
13
00:00:53,040 --> 00:01:03,540
So if I say something like print Hello enter and then if I were to do the exact same thing with a hash
14
00:01:03,540 --> 00:01:08,530
tag in front of it notice that I don't get any output because R won't read anything.
15
00:01:08,550 --> 00:01:11,510
Pass the hash tag because it treats it as just that comments.
16
00:01:11,520 --> 00:01:13,950
So that's one thing I want you to be aware of.
17
00:01:14,160 --> 00:01:20,460
And now let's go ahead and discuss variables and how to assign variables so variable names by convention
18
00:01:20,470 --> 00:01:20,900
.
19
00:01:21,120 --> 00:01:23,240
Start off with lower case letters.
20
00:01:23,520 --> 00:01:35,010
So if you had something like variable you would say use this assignment operator and then put in whatever
21
00:01:35,010 --> 00:01:37,410
you want to assign that variable.
22
00:01:37,440 --> 00:01:39,140
So what's actually happening here.
23
00:01:39,240 --> 00:01:40,560
We created a variable name.
24
00:01:40,560 --> 00:01:46,020
This case is called variable and we use the assignment operator which is this basically looks like an
25
00:01:46,020 --> 00:01:48,360
arrow which is nice for readability.
26
00:01:48,360 --> 00:01:52,860
So it's this less and and then a minus or a dash.
27
00:01:52,860 --> 00:01:58,440
So they form an arrow and then on the right hand side whatever data object or data type you want to
28
00:01:58,440 --> 00:01:59,520
assign to that very well.
29
00:01:59,520 --> 00:02:04,010
So for this lecturer it's going to be dealing with integers since that's something we've dealt with
30
00:02:04,020 --> 00:02:04,820
before.
31
00:02:05,130 --> 00:02:08,210
In the example of arithmetic.
32
00:02:08,460 --> 00:02:13,980
So here I am in signing the integer 100 to the variable called variable.
33
00:02:13,980 --> 00:02:20,910
So if I call variable again and then go ahead and just click enter in the council will return its assigned
34
00:02:20,910 --> 00:02:22,960
value which is 100.
35
00:02:22,980 --> 00:02:30,400
So let's go ahead and imagine another example will say bank and assignats 1000.
36
00:02:30,840 --> 00:02:35,050
So now if I call bank I get 1000 out as the assignments.
37
00:02:35,070 --> 00:02:37,500
So that's a variable assignment works.
38
00:02:37,560 --> 00:02:42,090
And you'll notice here in the environment if you ever want to know what variables you have or what values
39
00:02:42,090 --> 00:02:48,390
you have in your global environment for this session of Are You can reference this here.
40
00:02:48,390 --> 00:02:56,180
So just some quick style guides and convention points usually what you want to do is let's say you want
41
00:02:56,200 --> 00:02:59,340
to have multiple words in your variable name.
42
00:02:59,340 --> 00:03:04,290
What you would do is separate them by a period or dot.
43
00:03:04,440 --> 00:03:12,720
So we can say something like bank accounts and then assign that 100 so that's acceptable.
44
00:03:12,720 --> 00:03:20,250
Sometimes you also see this sort of notation bank and then instead of a dot They just write a capital
45
00:03:20,280 --> 00:03:22,560
A.
46
00:03:23,460 --> 00:03:31,240
What you won't see in our as often and is usually known as a bad style season.
47
00:03:31,290 --> 00:03:39,060
Underscore now it will still work completely So each of these is technically correct you can use all
48
00:03:39,060 --> 00:03:44,970
of these methods but the most common styles you'll see is this Fersen right here separating each of
49
00:03:44,970 --> 00:03:46,450
the words.
50
00:03:46,500 --> 00:03:48,390
All right.
51
00:03:48,390 --> 00:03:53,730
Later on when we discuss functions we'll go over the style guides for namea your functions and functions
52
00:03:53,730 --> 00:03:57,600
will actually usually start with capital letters.
53
00:03:57,600 --> 00:04:03,990
So finally just go ahead and show a quick simple example how you can use variables to perform calculations
54
00:04:04,050 --> 00:04:05,350
in operations that are.
55
00:04:05,460 --> 00:04:07,190
Let's go ahead and clear the cons..
56
00:04:07,400 --> 00:04:12,690
And here in Windows I'm clearing the consulars by doing control L as a shortcut for that.
57
00:04:12,720 --> 00:04:19,550
So I'm just going to go ahead and say make a variable deposit assign it.
58
00:04:19,860 --> 00:04:22,040
Let's just say 20 enter.
59
00:04:22,050 --> 00:04:31,350
So I have my deposit and I'm going to say bank accounts bank account and I'm going to reassign bank
60
00:04:31,530 --> 00:04:37,820
accounts as my current bank account plus my deposit.
61
00:04:37,860 --> 00:04:44,220
So notice here before I actually run this line my bank account variable is equal to 100.
62
00:04:44,220 --> 00:04:47,580
My deposit is equal to 20 after running this line.
63
00:04:47,580 --> 00:04:54,720
What's going to happen by click enter my bank account is going to be equal to 120.
64
00:04:54,930 --> 00:05:01,530
So that's going to be the 20 plus the previous 100 value of bank account and it's going to update that
65
00:05:01,530 --> 00:05:06,810
variable which is bank accounts and that's the basic way you can use variables in a variable assignment
66
00:05:06,810 --> 00:05:07,740
operations.
67
00:05:07,820 --> 00:05:11,750
In our ok player I think it's pretty straightforward.
68
00:05:11,760 --> 00:05:18,000
The main thing to go to this lecture is that this symbol this arrow symbol is what you're going to be
69
00:05:18,000 --> 00:05:21,440
using for variable assignments in our.
70
00:05:21,780 --> 00:05:22,320
Okay.
71
00:05:22,380 --> 00:05:23,240
Thanks everyone.
72
00:05:23,250 --> 00:05:24,170
I'll see you at the next lecture
7572
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.