There are two data sets:
x <- data.frame(c("мол", "ден", "свет")) y <- data.frame(c("молоко", "мебель", "светлый")) I do a cross join, I need to add a column to the result that shows whether the field from Х is contained in the field from Y.
There are two data sets:
x <- data.frame(c("мол", "ден", "свет")) y <- data.frame(c("молоко", "мебель", "светлый")) I do a cross join, I need to add a column to the result that shows whether the field from Х is contained in the field from Y.
According to my commentary, it’s not quite clear what you want to receive.
1) If your data.frame 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
- If you want to get a full match x with any y
x$x1=sapply(x[[1]],function(i) i %in%y)
- If you want to see the presence of x in any piece of the string y
x$x2=sapply(x[[1]],function(i) grepl(i,y))
- If you want to see the presence of x in y for 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 светлый Source: https://ru.stackoverflow.com/questions/477521/
All Articles
data.frameuseddata.frame. The solution for vectors and tables will be quite different. - Artem Klevtsov