Field A in field B on R



  • There are two data sets:

    x <- data.frame(c("мол", "ден", "свет"))
    y <- data.frame(c("молоко", "мебель", "светлый"))
    

    I make a cross of Join, I need to add a pole to the results, which shows whether a field is contained. Х field У



  • According to my company, it's not clear what you want.

    (1) If you have data.frame It's just text, you need to add. stringsAsFactors=F

    x <- data.frame (c("мол", "ден", "свет"),stringsAsFactors=F )
    y <- data.frame (c("молоко", "мебель", "светлый"),stringsAsFactors=F) 
    

    I see three possible options.

    (sighs) If you want a full match x with any y

    x$x1=sapply(x[[1]],function(i) i %in%y)

    (sighs) If you want to see, x in any piece of the line y

    x$x2=sapply(x[[1]],function(i) grepl(i,y))

    (sighs) If you want to see, x Total y each line x$x3=sapply(1:nrow(x),function(i) grepl(x[i,1],y[i,1]))

    > x
      c..мол....ден....свет..    x1    x2    x3 c..молоко....мебель....светлый..
    1                     мол FALSE  TRUE  TRUE                           молоко
    2                     ден FALSE FALSE FALSE                           мебель
    3                    свет FALSE  TRUE  TRUE                          светлый
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2