YouSub
Untitled

en English

Untitled English subtitles

0 downloads · 112 lines · added Oct 18, 2015

Report a problem
What's wrong?
Advertisement

English transcript

Hi! I am Mike Marin and in this video
we will get our first hands-on experience using R.
For the most part of this video we will discuss assigning values to objects in R,
basic arithmetic functions and a few other handy things to know
when getting started with R.
first we can assign a value to an object in R using the equal sign (=)
let's create an object called x
and store it with the value 11. If you would like to see
what is stored in an object, we can ask R
to "print" that object or
we may simply type the name of the object itself. You should know
that R is case sensitive. we can see if we take capital X
R returns an error message letting us know
there is no object capital X stored in R's memory
instead of using the equal sign
to assign values to objects we may also use the "less than sign
and a dash "-" to create an arrow. Here we'll assign the value 7
to the object "y". The choice to use the equal sign
or the arrow is simply a matter of preference
and usually the one that one chooses to use
really is just an artifact of which one they learned first
I prefer using the arrow but that's just my own personal choice
R will easily overwrite objects
for example if we try to sign the value 9 to y
the object y now has a value of 9
and the value of 7 has been
overwritten. To see what is stored in R's
memory or in the workspace we can take a look
up here at the workspace in R or
we may use the "ls command" to ask R
to let us know everything that stored in the workspace memory
we may remove an object
from the workspace memory using the "rm command"
here let's remove y from R's memory
we can now see the object y is not found
now let's just go back ahead and store the value 9 and y
because we're gonna come back to using this later. Object names in R
may include numbers or periods, for example
"x.1" is equal to say 14
Although the number may not appear as the first character
in the object's name, for example if we try to sign
the value of 22 to the object "1x"
we will see we are returned an error message; we may also assign
character values to objects in R rather than numbers
we can do this by including quotation marks
around the characters, for example
let's creaet an object xx and we will assign to it
the characters "marin".
We can now see these characters are stored in the object xx.
It's worth noting that if we include numbers in quotations in R
R will treat these as characters and not numeric
when performing operations on them. for example
if we assign a value in quotations "1"
to the object yy, R will treat
yy as a character not as a number.
We may perform arithmetic operations in R, for example 11
plus 14 is 25
7 times 9 is 63 . We may also perform the same
operations on objects in R. recall that we have stored
the value 11 in the object x and the value
9 in the object y. we can add
x and y together using the addition sign (+).
we may wish to store this
in a new object called z.
similarly we can subtract y from x
we can multiply x and y
or we can divide: x divided by y
we can also perform other arithmetic operations
for example we can square y
we can take x squared and add this
to y squared
we can take the square root of y using "sqrt command"
or we may simply take y
and raise it to the power of a half
we can take the natural logarithm or ln
using the "log command"
we can take the exponent of y
that is the anti log using the "exp command"
we can also calculate logs of other bases
for example log base 2 using the "log2 command"
we can calculate the absolute value using the "abs command"
here the absolute value of -14 is 14
We will end off this video by mentioning a few helpful things to know in R
The first is that if you've entered an incomplete command
R will follow that up with a plus sign (+) letting you know
there's an incomplete command. we can see if we don't complete this
R will still gives a plus sign. Once we add the
close parentheses to end this command
R will now return the square root of y to us.
A second thing worth knowing is a very handy shortcut:
using the "arrow up key" on the keyboard
will bring you to the last command that was entered in R
hitting the arrow key up again will bring you to the previously entered command
and so on. we can see every time we hit the arrow up key
this brings us to the previously entered command in R
we can hit the "arrow down key" to move forward
in the commands that have been entered
Finally one may want to include some writing
or comments within their code to remind themselves
of why they entered certain code when looking through things later on
for example you might want to have:" the code below
is for ..." so when you look back on this code a month later
you can remember why you were entering certain things
you'll notice that R gives an error here, it doesn't recognize this as being a command
including the number sign or hash (#)
in front of this will let R know to ignore
everything that follows after the number sign or the hash (#)
this will become useful as you start to write more lengthy code
and want to be able to include notes reminding you what you did in this code
In the next video we will discuss creating vectors and matrices
and performing some operations on these
Thanks for watching this video and make sure to check out my other instructional videos

Need subtitles from another video?