All language subtitles for 5. Vector Basics

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

1

Hello everyone and welcome to the lecture on vector basics and this lecture were to learn how to construct

2

the vector using the combined function the different rules about constructing a vector and how to use

3

the names function to assign names to each element in our vector.

4

Let's go ahead and jump to our studio to get started.

5

All right so here our studio and let's discuss the vector so vector is just a one dimensional array

6

that can hold character numeric or logical data elements and we create a vector by using the combined

7

function which is just the letter c of some parentheses.

8

So let's go ahead and create a couple of factors.

9

We'll start by creating a vector of numerics.

10

So I'll call this NBC as the variable name of the assignment operator that little arrow and then use

11

the combined function which is that C lose some parentheses and then pass an individual elements separated

12

by a comma.

13

So let's just say one two three four five separated by commas and notice in my environment I have NVC

14

and if I call NABC I get back my one dimensional array of those five elements and we can go ahead and

15

call class on NVC and all return numeric since every element in that vector is a numeric.

16

Let's go ahead and just see a couple more examples.

17

Let's say I wanted a vector of characters let's call it C C and we'll just go ahead and pass in USA

18

.

19

So you will say s a.

20

And remember to put in the C here for the combined function in order to actually create that vector

21

c v c and then we have USA.

22

All right.

23

And if I check the class it's going to return character.

24

Finally let's get a vector of logicals.

25

So those boolean values and we'll just say T capital T capital F stands for true false LGC is true false

26

.

27

And if I check the class of that it's a logical.

28

All right.

29

So something to note here is you may be wondering well what if I try to put in different data types

30

into a vector.

31

What would the class function return.

32

So one of the rules about vectors is that you can't mix data types into the elements of that vector

33

array R will convert the other elements to force everything to be of the same class.

34

We're going to show you an example of how that would work.

35

So going to create a variable v and then going to try to combine let's say a logical true with some

36

numbers 20 and 40.

37

So if I try doing that they'll notice if I call back that vector V that true has been converted to a

38

numeric one.

39

And that is going to be because everything else in that vector was numeric.

40

So if I call class on the.

41

Everything has been converted to a numeric.

42

Likewise if I put in false that false would have been converted to a 0 number.

43

Let's show you another example of mixing data types.

44

Let's say I had a character let's say just USA as a string and some numbers 20 31.

45

You might be thinking well how can USA be converted into a numeric.

46

Well in this case what are we going to do it's going to convert everything else into a character.

47

So everything matches the character of USA.

48

So if I call in class VI now everything in that vector is a character Scotius something to keep in mind

49

.

50

You can't mix up these data types elements in a vector.

51

Later on we'll learn about other data structures such as a list which will allow us to mix and match

52

different data types into an organizational array.

53

All right.

54

With that being said let's go ahead and talk about vector names.

55

So let's imagine we had a vector of temperature data.

56

So I go in and clear this make a new vector called temp's and put in some temperature data.

57

Let's go ahead and say 72 degrees 71 degrees and some other just numbers and good and fill these in

58

as you see fit 75.

59

So let's go ahead and make one for each week day so Monday Tuesday Wednesday Thursday Friday Saturday

60

Sunday.

61

All right.

62

So these are in Fahrenheit hopefully Celsius will be quite hot.

63

So we are temps.

64

And if you notice very cold temps back I have an array of numbers but no names to associate with each

65

of those temperatures stand for.

66

So I don't know if the Week starts at Sunday or Monday here and I want to add that information and I

67

can do that using the names function.

68

So I'm going to go ahead and say names pass in the vector that I want to name and then apply or assign

69

a vector of names for the temps vector.

70

So it's going to started off on Monday so I'll say Tuesday

71

Thursday

72

will say Friday Saturday Sunday say the sun makes sure that one last ones in single quotes or double

73

quotes.

74

OK so I've been able to assign names to each of these elements if I cold temps.

75

Now notice the output.

76

Now each of these temperatures has been assigned a name.

77

This is going to be really useful because now later on we learn about indexing vectors.

78

I can use these names to grab data out of the vector.

79

Something to note is that I don't have to keep rewriting this long vector of weekdays.

80

I could just assign this vector to let's say a vector called days may go ahead and do that in the press

81

on the up arrow on my keyboard and let's go ahead instead of using names here.

82

When I'm going to do is assigned this to a new vector called days.

83

So never called days.

84

I have this character vector of day information on Monday Tuesday etc. and then I can do this sort of

85

operation names temps

86

and assign days to it in this format.

87

So usually when you're doing names obviously will get the same result here same vector.

88

But as I mentioned usually in reading names you're not going to write this whole long vector multiple

89

times feasible times.

90

Your first assigned to a vector like so and then use that vector in your name assignment later on.

91

OK so let's just go over everything we learned just quickly throughout this lecture.

92

We learn how to use the combine function which is c and if you can go ahead and check out the history

93

here on this panel.

94

So we took out the combined function.

95

Learn how to use it learn that vectors can only take up one data type otherwise other data types will

96

be converted.

97

We learn how to use names and learn about the vector assignment.

98

OK later on we're going to learn much more about how to use and work with vectors in our.

99

Thanks everyone and I'll see you at the next lecture.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.