Video není dostupné.
Omlouváme se.

R Tutorial : Relational Operators in R

Sdílet
Vložit
  • čas přidán 4. 12. 2015
  • Want to learn more? Take the full course at learn.datacamp... at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
    ----
    Hi, and welcome to the first video of the intermediate R course. My name is Filip, I'm a content creator at DataCamp and I will help you master a bunch of new concepts in the R programming language. Next stop on our trip through the wonderful world of R: Relational operators!
    Relational operators, or comparators, are operators that help us see how one R object relates to another. For example, you can check whether two objects are equal. You can do this by using a double equals sign. We can, for example, see if the logical value `TRUE` equals the logical value `TRUE`. Let's try it out in the console: we type TRUE equals equal TRUE. The result of this query is a logical value, in this case, `TRUE`, because `TRUE` equals `TRUE`. On the contrary, TRUE == FALSE will give us `FALSE`. Makes sense, right?
    Apart from logical variables, we can also check the equality of other types. We can also compare strings (pt) and numbers (pt).
    The opposite of the equality operator, is the inequality operator, written as an exclamation mark followed by an equals sign. This sentence (pt) would read as: "hello" is not equal to "goodbye". Because this statement is correct, R will output `TRUE`. Naturally, the inequality operator can also be used for numerics, logicals and other R objects. See how every time, the result of the equality operator, is opposite for the inequality operator.
    Of course, there are also cases where you need more than simply equality and inequality operators. What about checking if an R object is 'less than' or 'greater than' another R object? This will not come as a surprise: you can use the less-than and greater-than sign for this. In the case of numerical values, here is a straightforward example: 3 less than 5 will evaluate to `TRUE`, while 3 greater than 5 will evaluate to `FALSE`.
    For numerics this makes sense, but how would this work for character strings and logical values? Is "Hello" greater than "Goodbye"? Let's find out! Apparently "Hello" greater than "Goodbye" evaluates to `TRUE`, but why so? It's because R uses the alphabet to sort character strings. Since "H" comes after "G" in the alphabet, "Hello" is considered greater than "Goodbye".
    How about logical values? Is `TRUE` less than `FALSE`? The following query gives us the answer. It appears not; it evaluates to FALSE. That's because under the hood, TRUE corresponds to 1 and FALSE corresponds to 0. And of course 1 is not less than 0, hence the FALSE result.
    You can also check to see if one R object is greater than or equal to (or less than or equal to) another R object. To do this, you can use the less than sign, or the greater than sign, together with the equals sign. So 5 greater than or equal to 3 as well as 3 greater than or equal to 3 will evaluate to TRUE.
    You already knew that R is pretty good with vectors. How about R's comparators, can they also handle vectors? Suppose you have recorded the daily number of views your linkedin profile had the previous week and stored them in a vector `linkedin`. If we want to find out on which days the number of views exceeded 10, we can directly use the greater than sign. For the first, third, sixth and seventh element in the vector, the number of views is greater than 10, so for these elements the result will be TRUE.
    You can also compare vectors to vectors; suppose you also recorded the number of views your facebook profile had the previous week and saved them in another vector, `facebook`. When are the number of facebook views less than or equal to the number of linkedin views? The following expression shows us how to calculate this
    Does it make sense? In this case, the comparison is done for every element of the vector, one by one. For example, in the third day, the number of facebook views is 5 and the number of linkedin views is 13. The comparison evaluates to `TRUE`, as 5 is smaller than or equal to 13.
    Just as for vectors, R also knows how to compare other data structures, such as matrices and lists. Head over the interactive exercises and add Relational Operators to your ever growing R skillset!
    #DataCamp #RTutorial #IntermediateR

Komentáře • 8

  • @user-uq3qh2cy9v
    @user-uq3qh2cy9v Před 4 lety +3

    Hi, could you please release the next four videos? Thank you!

  • @bca-gv6zs
    @bca-gv6zs Před 4 lety +4

    The next four videos were set to be private, could you release them again?

  • @valeFarez
    @valeFarez Před 3 lety

    Thanks for creating this content. It is really helpful!!

  • @shashikanttyagi7452
    @shashikanttyagi7452 Před 2 lety

    Thanks for this

  • @legendcomix9228
    @legendcomix9228 Před 3 lety

    Really awsome 💥💥💥💥 helped a loottt

  • @HossainSkSabbir
    @HossainSkSabbir Před 4 lety

    Could you please release the next four videos again? Or would you suggest other links to visit?

  • @raminbahmani9991
    @raminbahmani9991 Před 4 lety

    Could you please release the four next videos as well?

  • @professorabdullah7756
    @professorabdullah7756 Před 3 lety

    I want to partition a vector containing elements from 1 to 19 into 4 parts [1,2,3,4,5], [6,7,8,9,10], [11,12,13,14,15] and [16,17,18,19]. how can I do it?