Video není dostupné.
Omlouváme se.

R tutorial: The basic data types in R

Sdílet
Vložit
  • čas přidán 18. 08. 2024
  • In this video you will understand what the basic data types are in R.
    Want to take the interactive coding exercises and earn a certificate? Join DataCamp today, and start the free introduction to R tutorial: www.datacamp.c...
    In the previous video you saw that R is also know as the Language for Statistical Computing. Data is the center of any statistical analysis, so let me introduce you to some of R's fundamental data types, also called atomic vector types. Throughout our experiments, we will use the function class(). This is a useful way to see what type a variable is. Let's head over to the console and start with TRUE, in capital letters.
    TRUE is a logical. That's also what class(TRUE) tells us. Logicals are so-called boolean values, and can be either `TRUE` or `FALSE`.
    Well, actually, `NA`, to denote missing values, is also a logical, but I won't go into detail on that here. `TRUE` and `FALSE` can be abbreviated to `T` and `F` respectively, as you can see here. However, I want to strongly encourage you to use the full versions, `TRUE` and `FALSE`.
    Next, let's experiment with numbers. The values 2 and 2.5 are called numerics in R. You can perform all sorts of operations on them such as addition, subtraction, multiplication, division and many more. A special type of numeric is the integer. It is a way to represent natural numbers like 1 and 2. To specify that a number is integer, you can add a capital L to them.
    You don't see the difference between the integer 2 and the numeric 2 from the output. However, the `class()` function reveals the difference.
    Instead of asking for the class of a variable, you can also use the is-dot-functions to see whether variables are actually of a certain type. To see if a variable is a numeric, we can use the is-dot-numeric function.
    It appears that both are numerics. To see if a variable is integer, we can use is-dot-integer.
    This shows us that integers are numerics, but that not all numerics are integers, so there's some kind of type hierarchy going on here.
    Last but not least, there's the character string. The class of this type of object is "character".
    It's important to note that there are other data types in R, such as double for higher precision numerics, complex for handling complex numbers, and raw to store raw bytes. However, you will have tons of fun working with numerics, integers, logicals and characters in the remainder of this introductory course so we'll leave these alone for now.
    There are cases in which you want to change the type of a variable to another one. How would that work? This is where coercion comes into play! By using the as dot functions one can coerce the type of a variable to another type. Many ways of transformation between types are possible. Have a look at these examples.
    The first command here coerces the logical TRUE to a numeric. FALSE, however, coerces to the numeric zero. We can also coerce numerics to characters. But what about the other way around? Can you also coerce characters to numerics? Sure you can!
    You can even convert this character string, "4.5", to an integer, but this implies some information loss, because you cannot keep the decimal part here. But beware: coercion, as in converting data types, is not always possible. Let's try to convert the character "Hello" to a numeric.
    This conversion outputs an NA, a missing value. R doesn't understand how to transform "Hello" into a numeric, and decides to return a Not Available instead.
    You already have the essentials on what R is, how to use its basic features and what are the most important data types you will encounter in your R quest. Now head over to the exercises and I'll see you in the next chapter!

Komentáře • 18

  • @ActuaryEducation
    @ActuaryEducation Před 8 lety +7

    There is a little mistake in this video. Numerics are subdivided into double and integer depending on how they are stored in the memory. "Double" refers to the double precision - ie the two numbers in scientific form eg 3.208 × 10^3 - the 2 numbers herer are 3.208 and 3.
    By default numerics are double. It's only if you specify as an integer eg 2L that you force R to not use scientific form to store the number.

  • @robhuntington8504
    @robhuntington8504 Před 4 lety

    so helpful to have the transcript in the description. I'm making a studying slide deck with screen shots and was gonna use CZcams transcript but it has the timestamps after every sentence. annoying having to remove them.

  • @danishnabeel2101
    @danishnabeel2101 Před 6 lety +5

    where are the practice exercises?

  • @junglebit6886
    @junglebit6886 Před 7 lety +1

    Very good video, thank you so much

  • @poojamahesh8594
    @poojamahesh8594 Před 3 lety

    Sir, I have a data set containing variable "Accident Time ", it is in int type.. Please suggest to which data type I must convert them... Please

  • @fffppp8762
    @fffppp8762 Před 7 lety +1

    looks interesting

  • @Reivivus
    @Reivivus Před 7 lety

    I always found the datatype of a variable in R with the structure str() function.

    • @harvindersingh-xb2pz
      @harvindersingh-xb2pz Před 6 lety

      Reivivus i think R is similar to Ruby, there is more than one way to get the same answer. So somebody may do it differently. But im not sure how similar it is to Ruby but i can see that its similar in the sense of different methods.

  • @surthinenilavanyavalmiki4598

    how to extract the data which is saved in Excel to R?

  • @coolgomsy89
    @coolgomsy89 Před 7 lety

    From where I can get this tool to run on my machine?

  • @muhammadsuleman1741
    @muhammadsuleman1741 Před 2 lety

    how can I download the R console on my pc

  • @ButterfaceGMusicSlump
    @ButterfaceGMusicSlump Před 5 lety

    what's the value of stew? 1:04 LOL

  • @mdvenkatesh4234
    @mdvenkatesh4234 Před 8 lety

    why do underscore(_)i s making more sense
    ex-_my _oranges is having no problem while excution while my oranges apper to be error

    • @munnat8073
      @munnat8073 Před 7 lety

      md venkatesh space must not be there

  • @poojaprajapati1019
    @poojaprajapati1019 Před 6 lety +1

    I want to make a function in which i can calculate the sum of all the characters which I've already stored (eg.-H=1, C=12)
    Input would be like
    HHCCCNNNOOO

  • @edongoogle8290
    @edongoogle8290 Před 4 lety

    I struggle to understand what he says. I can, but I have to focus on deciphering his accent more than on the code on screen :/. I'm a native English speaker.