DATA SCIENCE WITH R | June 20 | Priyanka

Discussion in 'Big Data and Analytics' started by Sriraksha G, Jun 20, 2020.

  1. Sriraksha G

    Sriraksha G Active Member
    Simplilearn Support

    Joined:
    Dec 12, 2019
    Messages:
    31
    Likes Received:
    34
    #1
  2. priyanka_217

    priyanka_217 Priyanka Dhoot
    Customer

    Joined:
    Jul 23, 2019
    Messages:
    130
    Likes Received:
    5
    Hi Everyone..
     
    #2
  3. Akhila Pavithran

    Akhila Pavithran New Member

    Joined:
    May 18, 2020
    Messages:
    1
    Likes Received:
    0
    Q. What does the %in% operator do?

    > A=c(1,2,3,4)
    > A%in%3
    [1] FALSE FALSE TRUE FALSE

    The %in% operator checks and tells us if a certain value (e.g., 3) is present in a previously defined variable (e.g., A). Here there are four values in A. The %in% operator checks if these values are equal to 3 and gives me a TRUE/FALSE output in case of a match/no match, respectively.
     
    #3
  4. Mukund Ramasubramanian

    Alumni

    Joined:
    May 11, 2020
    Messages:
    10
    Likes Received:
    2
    Nested If Else:

    Code:

    x<-25
    if(x>0){
    print("Positive Number")
    }elseif(x<0){
    print("Negative Number")
    }else{
    print("Zero")
    }

    Error:

    Error: unexpected '}' in "}"

    Where have i missed the '}'?
     
    #4
  5. Prateek Jain_10

    Joined:
    Feb 27, 2020
    Messages:
    3
    Likes Received:
    3
    Hi Priyanka, Thank you for today's session. Following is today's session's assignment:

    Q1. What does the following operator do?

    %in%

    Ans: This operator is used to identify if an element belongs to a vector.

    A <- 8
    B <- 12
    C <- 1:10
    print(A %in% C)
    print(B %in% C)

    Values under GE:
    A=8 , B=12 , C= int [1:10] 1 2 3 4 5 6 7 8 9 10

    The Result would be:

    > A <- 8
    > B <- 12
    > C <- 1:10
    > print(A %in% C)
    [1] TRUE
    > print(B %in% C)
    [1] FALSE
    >

    As element A belongs to C, hence result came as "TRUE". However, element B is not part of C, hence we got result as "False".

    Hope i have understood it correctly. Please let me know if i have done any mistake or if the understanding is wrong. Thank you.
     
    #5
  6. Thamilselvan Chinnasamy

    Joined:
    May 17, 2020
    Messages:
    3
    Likes Received:
    3

    > #Day 02 Assignment

    > # purpose of %in% operator
    > # to identify the presence of a value in a vector
    > in_condn<-c(1:10)
    > courses<-c("R","Python")
    > A=10
    > Name="R"
    > A %in% in_condn
    [1] TRUE
    > Name %in% courses
    [1] TRUE
     
    #6
    priyanka_217 likes this.
  7. Sahithi Katreddi

    Joined:
    Jun 11, 2020
    Messages:
    5
    Likes Received:
    4
    Hi,

    I am Sahithi Katreddi. Please find my assignment code output attached along with this post.

    My answer for the assigment is : The '%in%' operator is used to check if the value of one variable is present in the other variable. The variables can be single valued variables or collection of values.

    Kindly let me know if I am wrong anywhere.
     

    Attached Files:

    #7
  8. Sahithi Katreddi

    Joined:
    Jun 11, 2020
    Messages:
    5
    Likes Received:
    4
    Hi Mukund,

    I think it is because of the indentation in R, due to which these errors are popping up. Please try the below code :

    x<-25
    if (x>0){print('Positive number')} else if (x<0){print('Negative number')} else {print('Zero')}

    Please correct me if i am wrong anywhere.
     
    #8
  9. Satyajit Datta

    Simplilearn Support

    Joined:
    Jan 31, 2017
    Messages:
    12
    Likes Received:
    4

    Hi Mukund,
    Seems the error is not in the curly braces. Rather elseif is not one word; It should be else if.
    Try below code:

    x <- 25
    if(x>0) {
    print("Positive Number")
    }else if(x<0){
    print("Negative Number")
    }else{
    print("Zero")
    }
     
    #9
  10. Shrikant Shriniwas Biyani

    Joined:
    Oct 12, 2019
    Messages:
    2
    Likes Received:
    0
     
    #10
  11. Shrikant Shriniwas Biyani

    Joined:
    Oct 12, 2019
    Messages:
    2
    Likes Received:
    0
    X = 25
    > X<-25
    > if(X>0){
    + print("Positive Number")
    + }else if (X<0){print("Negative Number")
    + }else
    + print("Zero")

    Try this you will have result.
     
    #11
  12. Shashwat_8

    Shashwat_8 New Member

    Joined:
    Jun 15, 2020
    Messages:
    1
    Likes Received:
    0
    Hello everyone!
    Today's assignment >>>>
    # Shashwat
    ##Assignment
    a <- 10
    a1 <- 18
    b <- 1:16
    print(a %in% b)
    print(a1 %in% b)

    #output in Console

    > a <- 10
    > a1 <- 18
    > b <- 1:16
    > print(a %in% b)
    [1] TRUE
    > print(a1 %in% b)
    [1] FALSE
     
    #12
  13. Winston Cherian

    Joined:
    May 19, 2020
    Messages:
    3
    Likes Received:
    3
    x<-25
    if(x>0){
    print("Positive Number")
    }else if(x<0){
    print("Negative Number")
    }else
    print("Zero")

    { } not required. print("zero")
     
    #13
    Swati Ghosh likes this.
  14. Winston Cherian

    Joined:
    May 19, 2020
    Messages:
    3
    Likes Received:
    3
    %in% operator in R, is used to identify if an element belongs to a vector.

    EXAMPLE 1
    # R %in% operator
    v1 <- 3
    v2 <- 101
    t <- c(1,2,3,4,5,6,7,8)
    v1 %in% t
    In the above example v1 is present in t, so the output will be
    [1] TRUE

    EXAMPLE 2
    # R %in% operator
    v1 <- 3
    v2 <- 101
    t <- c(1,2,3,4,5,6,7,8)
    v2 %in% t
    v2 is not present in t, so the output will be
    [1] FALSE
     
    #14
    Sahana_19 and Anju Singh_2 like this.
  15. Swathi KB

    Swathi KB New Member

    Joined:
    Jun 10, 2020
    Messages:
    1
    Likes Received:
    0
    Assignment - %in%

    This operator is used to identify if an element belongs to a vector.
    v1 <-8
    v2 <-12
    t <-1:10
    print(v1 %in% t)
    print(v2 %in% t)

    Result of above code snippet :
    > v1 <-8
    > v2 <-12
    > t <-1:10
    > print(v1 %in% t)
    [1] TRUE
    > print(v2 %in% t)
    [1] FALSE
     
    #15
  16. Anju Singh_2

    Anju Singh_2 Member

    Joined:
    Apr 30, 2020
    Messages:
    3
    Likes Received:
    1
    readline is used to take input from user. as.integer is used to return that input as integer. We asked this question in class, here is the answer.
     
    #16
  17. Satyajit Datta

    Simplilearn Support

    Joined:
    Jan 31, 2017
    Messages:
    12
    Likes Received:
    4
    #17
  18. Satyajit Datta

    Simplilearn Support

    Joined:
    Jan 31, 2017
    Messages:
    12
    Likes Received:
    4
    Distribution of data required to use models:

    Thank you for an informative session today.

    Have the below doubt.
    Heard that in order to apply a model, the data must have normal distribution or we should convert it to normal distribution.
    1. Why is normal distribution required to apply a model? I can understand removing outliers, but not why distribution must be normal.
    2. How can we convert to a normal distribution if the sample or population data does not have normal distribution?
    3. Does it mean we cannot apply models unless the distribution is normal?
    Regards,
    Satyajit
     
    #18
  19. Mukund Ramasubramanian

    Alumni

    Joined:
    May 11, 2020
    Messages:
    10
    Likes Received:
    2
    %in% is like an intersection operation used in sets. If we have three variables and we need to check the presence of the value of one of the declared variables in another variable, we can make use of the %in% operator.
    For instance, we have three variables namely d, e, and f, wherein d<-c(1,2,3,4,5,6,7,8,9,10), e<-c(10,22,32,43) and t<-c(1,2,3,4,5,6,7,8,9,10,23,45,68).
    When we use the operator as,
    d%in%f, the output will be TRUE as the values stored in d are present in f.
    Similarly if we code in the following,
    e&in%f
    the output will be FALSE as none of the values in e re present in f
     
    #19
  20. Ivy Sengupta

    Ivy Sengupta Member
    Alumni

    Joined:
    Jun 17, 2020
    Messages:
    7
    Likes Received:
    4
    Assignment 1: %in%

    %in% is used the to check weather a particular element or group of elements is present in the list or not. If the element is present in the list then it will return TRUE otherwise it will return FALSE. It checks element by element.

    Code:

    > num_list<-c(1:5)

    > print(num_list)

    [1] 1 2 3 4 5

    > x<-4

    > print(x%in%num_list)

    [1] TRUE

    > y<-10

    > print(y%in%num_list)

    [1] FALSE

    > z<-c(2:4)

    > print(z)

    [1] 2 3 4

    > print(z%in%num_list)

    [1] TRUE TRUE TRUE

    > m<-c(2,6,5)

    > print(m)

    [1] 2 6 5

    > print(m%in%num_list)

    [1] TRUE FALSE TRUE
     
    #20
  21. Ridhi Fomra

    Ridhi Fomra New Member

    Joined:
    Apr 21, 2020
    Messages:
    1
    Likes Received:
    0
    #Assignment - %in% operator in R
    > vec<-c(1,2,3,4,5,6,7,8,9,10)
    > 3:8%in%1:10
    [1] TRUE TRUE TRUE TRUE TRUE TRUE
     
    #21
  22. Deepak Aryaselhi

    Deepak Aryaselhi New Member

    Joined:
    May 29, 2018
    Messages:
    1
    Likes Received:
    0
    Tried %in%, this is to check if the value from one Variable is present as exactly 'in' the other variable. for example, i tried the below code and got the result in console:
    # %in%
    A <- 8
    B <- 9
    C <- 1:10
    print(A %in% C)
    print(B %in% C)

    Result in console:
    > C <- 1:10
    > A <- 8> B <- 9> print(B %in% C)[1] TRUE> print(A %in% C)[1] TRUE

    If the value is changed for B which is not available in C<- 1:10, the below is the code and result:
    A <- 8
    B <- 12
    C <- 1:10
    print(A %in% C)
    print(B %in% C)

    Result in console:
    > print(B %in% C)[1] FALSE

    now the result is FALSE for B 'in' C
    so basically this is use to check if present 'in' other variable or vector. Any suggestions, pls help..
     
    #22
  23. priyanka_217

    priyanka_217 Priyanka Dhoot
    Customer

    Joined:
    Jul 23, 2019
    Messages:
    130
    Likes Received:
    5
    G
    Great....
     
    #23
  24. priyanka_217

    priyanka_217 Priyanka Dhoot
    Customer

    Joined:
    Jul 23, 2019
    Messages:
    130
    Likes Received:
    5
    Perfect...great..Keep practising
     
    #24
  25. vrmmohan(3345206)

    vrmmohan(3345206) New Member
    Alumni

    Joined:
    Dec 9, 2014
    Messages:
    1
    Likes Received:
    1
    R-Assignment.png R-Assignment.png R-Assignment.png R-Assignment.png
     
    #25
    priyanka_217 likes this.
  26. priyanka_217

    priyanka_217 Priyanka Dhoot
    Customer

    Joined:
    Jul 23, 2019
    Messages:
    130
    Likes Received:
    5
    Hi
    Mukund,

    elseif is not a single word. Need space between them

    if(x>0){
    print("Positive Number")
    }else if(x<0){
    print("Negative Number")
    }else{
    print("Zero")
    }
     
    #26
  27. priyanka_217

    priyanka_217 Priyanka Dhoot
    Customer

    Joined:
    Jul 23, 2019
    Messages:
    130
    Likes Received:
    5

    Great Job..Keep practsing..
     
    #27
  28. priyanka_217

    priyanka_217 Priyanka Dhoot
    Customer

    Joined:
    Jul 23, 2019
    Messages:
    130
    Likes Received:
    5
    Great Job..Keep practsing..
     
    #28
  29. priyanka_217

    priyanka_217 Priyanka Dhoot
    Customer

    Joined:
    Jul 23, 2019
    Messages:
    130
    Likes Received:
    5
    Great Job..Keep practsing..
     
    #29
  30. priyanka_217

    priyanka_217 Priyanka Dhoot
    Customer

    Joined:
    Jul 23, 2019
    Messages:
    130
    Likes Received:
    5
    Great Job..Keep practsing..
     
    #30
  31. Anju Singh_2

    Anju Singh_2 Member

    Joined:
    Apr 30, 2020
    Messages:
    3
    Likes Received:
    1
    temp1 <- c(12,23,12,34,45)
    temp2 <- c(12,23,34,45,15)
    temp3 <- c(11,12,13,14,35)
    temp4 <- c(12,12,23,24,45)

    temp_vec <- c(temp1, temp2, temp3, temp4)

    for(i1 in 1:length(temp_vec))
    {
    if(temp_vec(i1)%/%2==0)

    paste("This number is Even" ,temp_vec(i1))
    }

    for(j in 1:length(temp1))
    {
    for (k in 2:temp1[j]-1)
    {
    if(temp1[k]%/%2 == 0)
    print(temp1[j], "is not prime ")
    }
    }


    Hey Priyanka, could you pls help me identify error. Both are not working. Neither Even function nor Prime.
     
    #31
    priyanka_217 likes this.
  32. D PRIYA RAKSHAA

    Joined:
    May 17, 2020
    Messages:
    3
    Likes Received:
    3
    D Priya Rakshaa

    Assignment :- %in% Operator


    %in% operator identifies if an element belongs to a vector

    CODE :-
    A=c(2,3,5,7,9)
    B=5
    C=8
    print(B%in%A)
    print(C%in%A)

    RESULT WHEN RUN :-

    > A=c(2,3,5,7,9)> B=5> C=8> print(B%in%A)[1] TRUE> print(C%in%A)[1] FALSE
     
    #32
    priyanka_217 likes this.
  33. Suvendu Das

    Suvendu Das New Member

    Joined:
    May 17, 2020
    Messages:
    1
    Likes Received:
    0
    Day 02 Assignment

    %in% operator identifies if an element belongs to a vector

    CODE :-
    Z=c(2,4,8,7,10)
    Y=c(1,3,6,9,5)
    C=8
    print(C%in%Z)
    print(C%in%Y)

    In RUN Command

    > Z=c(2,3,5,7,9)
    > Y=c(1,3,6,9,5)
    > C=8
    > print(C%in%Z)
    [1] TRUE
    > print(C%in%Y)
    [1] FALSE
     
    #33
  34. Devang Tadvi

    Devang Tadvi New Member

    Joined:
    Jun 15, 2020
    Messages:
    1
    Likes Received:
    1
    %in% helps us to check value exists in another vector or not. it will return bool value upon using %in% operator.
    below is my example:

    # Assignment %in%
    > a = 3
    > b= c(1,2,3,4,5,6,7,8)
    > a %in% b
    [1] TRUE
    > a=13
    >
    > a %in% b
    [1] FALSE
     
    #34
    priyanka_217 likes this.
  35. Mohammed Habeeb_1

    Joined:
    Jun 10, 2020
    Messages:
    2
    Likes Received:
    1
    Assignment: How this operator work %in%
    Explanation:
    #This operator is used to identify if an element belongs to a vector or not, If an element present in the vector output will be TRUE otherwise FALSE. (Boolean value).
    #%in% operator testing
    v1 <- 3
    v2 <- 11
    t <- 1:10
    v1
    v2
    t
    print(v1 %in% t)
    print(v2 %in% t)

    Output :
    > v1 <- 3
    > v2 <- 11
    > t <- 1:10
    > v1
    [1] 3
    > v2
    [1] 11
    > t
    [1] 1 2 3 4 5 6 7 8 9 10
    > print(v1 %in% t)
    [1] TRUE
    > print(v2 %in% t)
    [1] FALSE
     
    #35
    priyanka_217 likes this.
  36. KANDHALA PRAVEEN KUMAR

    Joined:
    Jun 15, 2020
    Messages:
    2
    Likes Received:
    2
    %in% operator use in R

    This operator is used to identify if an element belongs to a vector.

    example:
    v1 <-20
    v2 <-50
    t <-1:30
    print(v1 %in% t)
    print(v2 %in% t)
    it produces the following result −

    [1] TRUE
    [1] FALSE
     
    #36
    priyanka_217 likes this.
  37. Sahana_19

    Sahana_19 Member

    Joined:
    Jun 15, 2020
    Messages:
    3
    Likes Received:
    2
    Definition: %in% operator is used to identify the presence of particular element in a given vectors, if the element is present in a given vector then value will return bool value i.e TRUE else if the element is not present then it will return False.

    # Assignment:1
    -------- %in% operator in R-------
    example:1
    with character vectors :
    c("d", "e") %in% c("a", "b", "c", "d")
    [1] TRUE TRUE TRUE FALSE FALSE

    example:2
    with integer vectors :
    6:10 %in% 1:8
    [1] TRUE TRUE TRUE FALSE FALSE
     
    #37
    priyanka_217 likes this.
  38. Haritha Reddy

    Haritha Reddy New Member

    Joined:
    Oct 5, 2019
    Messages:
    1
    Likes Received:
    1
    #Assignment 1
    %in% operator is used to identify if an element belongs to a given vector with output in Boolean form.
    ex:
    A=c(1,2,13,'A')
    V<- c(1:10,'A')
    print(A%in%V)
    [1] TRUE TRUE FALSE TRUE
     
    #38
    priyanka_217 likes this.
  39. Mohammed Ashif A

    Joined:
    Jun 5, 2020
    Messages:
    2
    Likes Received:
    1
    What does the %in% operator do?
    in% operator in R, is used to identify if an element belongs to a vector.

    Example:-
    Loop2=10:17(Under the Loop2 Dataset I am Looking for the Value 11 where is present.)

    loop2%in%11
    [1] FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
     
    #39
    priyanka_217 likes this.
  40. Mahaboob Ahmed

    Joined:
    Jun 10, 2020
    Messages:
    2
    Likes Received:
    3
    #This operator is used to identify if an element belongs to a vector or not, But give the ouput TRUE or FALSE.

    #%in% testing

    v1 <- 3

    v2 <- 11

    t <- 1:10

    v1

    v2

    t

    print(v1 %in% t)

    print(v2 %in% t)

    OUTPUT :

    > t [1] 1 2 3 4 5 6 7 8 9 10
    > print(v1 %in% t)
    [1] TRUE
    > print(v2 %in% t)
    [1] FALSE
     
    #40
    priyanka_217 likes this.
  41. Mukund Ramasubramanian

    Alumni

    Joined:
    May 11, 2020
    Messages:
    10
    Likes Received:
    2
     
    #41
  42. Mohammed Ashif A

    Joined:
    Jun 5, 2020
    Messages:
    2
    Likes Received:
    1
    I am trying to execute below Command
    Y=c(2,3)
    X=c(10,9,8,7,6)
    X&Y = [1] TRUE TRUE TRUE TRUE TRUE

    X|Y = [1] TRUE TRUE TRUE TRUE TRUE

    Y&&X = [1] TRUE

    Y||X = [1] TRUE

    Y and X have different set of numbers
    but still i am Getting as TRUE result
    let me know How the logic works here.
     
    #42
  43. Akshay Nagaraja

    Joined:
    Jun 11, 2020
    Messages:
    2
    Likes Received:
    2
    # Assignment 1 Dt 21-Jun-20
    # What is "%in%" ?
    # Ans: %in% is an R operator used to find presence of specific value in a range/ sequence of data
    # Example:
    A <- 3
    B <- 9
    C <- 1:8
    print(A%in%C)
    print(B%in%C)
    # Result
    # TRUE - since 3 is present in the sequence
    # FALSE - since 9 is out of range in the defined sequence
     
    #43
    priyanka_217 likes this.
  44. Bibin Varghese_1

    Bibin Varghese_1 New Member

    Joined:
    Jun 17, 2020
    Messages:
    1
    Likes Received:
    1
    Assignment %in%.
    This code is used to identify if an element belongs to a vector.

    for Eg:-

    v1 <- c(1:5)
    v2 <- c(1:7)
    v3 <- c(5:10)
    print(v1%in%v3)
    print(v2%in%v3)

    And the result will be :-
    > print(v1%in%v3)
    [1] FALSE FALSE FALSE FALSE TRUE> print(v2%in%v3)[1] FALSE FALSE FALSE FALSE TRUE TRUE TRUE
    upload_2020-6-26_22-41-39.png
     
    #44
    priyanka_217 likes this.
  45. Dakshata (4083)

    Dakshata (4083) New Member

    Joined:
    Mar 11, 2014
    Messages:
    1
    Likes Received:
    1
    %in% operator in R helps identify whether an element belongs to a vector


    # R %in% operator
    v1 <- 3
    v2 <- 101
    t <- c(1,2,3,4,5,6,7,8)
    v1 %in% t
    In the above example v1 is present in t, so the output will be
    [1] TRUE


    # R %in% operator
    v1 <- 3
    v2 <- 101
    t <- c(1,2,3,4,5,6,7,8)
    v2 %in% t
    v2 is not present in t, so the output will be
    [1] FALSE
     
    #45
    Last edited: Jun 26, 2020
    priyanka_217 likes this.
  46. Syed Rizwan Ali

    Joined:
    Jun 10, 2020
    Messages:
    2
    Likes Received:
    2
    Assignment: How this operator work %in%
    Explanation:
    #This operator is used to identify if an element belongs to a vector or not, If an element present in the vector output will be TRUE otherwise FALSE. (Boolean value).
    #%in% operator testing
    v1 <- 3
    v2 <- 11
    t <- 1:8
    v1
    v2
    t
    print(v1 %in% t)
    print(v2 %in% t)
    Output :
    > v1 <- 3
    > v2 <- 11
    > t <- 1:8
    > v1
    [1] 3
    > v2
    [1] 11
    > t
    [1] 1 2 3 4 5 6 7 8
    > print(v1 %in% t)
    [1] TRUE
    > print(v2 %in% t)
    [1] FALSE
     
    #46
    priyanka_217 likes this.
  47. Rajesh John Mathew

    Rajesh John Mathew New Member

    Joined:
    Mar 31, 2020
    Messages:
    1
    Likes Received:
    1
    Assignment Query: Purpose of %in%

    Prima facie,through basic web search on http://www.google.com,an operator that exercises value matching from a vector to identify an element.

    Example:

    v1 <- 3
    v2 <- 101
    t <- c(1,2,3,4,5,6,7,8)
    v1 %in% t

    v1 is present in t; the output will be TRUE.

    Reference:
    Paraphrased and sourced from http://www.datasciencemadesimple.com/in-operator-in-r/ and https://stackoverflow.com/questions/42637099/difference-between-the-and-in-operators-in-r/42637186,accessed on 27-06-2020 at 07:42 am.
     
    #47
    priyanka_217 likes this.
  48. Bitan Biswas

    Bitan Biswas New Member

    Joined:
    Jun 8, 2020
    Messages:
    1
    Likes Received:
    1
    Assignment- The %in% operator in R is used to identify if any element is present in a vector.

    #R %in% operator

    > v1<- 12
    > v2<- 45
    > v3<- 28
    > t<- c(10, 12, 15, 25, 28, 36, 44)
    > v1 %in% t
    [1] TRUE
    > v2 %in% t
    [1] FALSE
    > v3 %in% t
    [1] TRUE
     
    #48
    priyanka_217 likes this.
  49. Satyajit Datta

    Simplilearn Support

    Joined:
    Jan 31, 2017
    Messages:
    12
    Likes Received:
    4
    Kindly clarify
     
    #49
    priyanka_217 likes this.
  50. Thamilselvan Chinnasamy

    Joined:
    May 17, 2020
    Messages:
    3
    Likes Received:
    3
    Assignment #3: populate 3 rows using matrix function.
    x = matrix(1:12,3,4,byrow=TRUE)
    x[c(1,2,3),c(3,4)]
     
    #50
    priyanka_217 likes this.

Share This Page