I want to compare two string vectors as follows:
Test1<-c("Everything is normal","It is all sunny","Its raining cats and dogs","Mild")
Test2<-c("Everything is normal","It is thundering","Its raining cats and dogs","Cloudy")
Filtered<-data.frame(Test1,Test2)
Intended output:
Number the same: 2
Number present in Test1 and not in Test2: 2
Number present in Test2 and not in Test1: 2
I would also like to see which strings are different so that the other intended output should be as follows (and also part of the original dataframe)
Same<-c("Everything is normal","Its raining cats and dogs")
OnlyInA<-c("It is all sunny")
OnlyInB<-c("It is thundering","Cloudy")
I have tried:
Filtered$Same<-intersect(Filtered$A,Filtered$B)
Filtered$InAButNotB<-setdiff(Filtered$A,Filtered$B)
but when I try the last line I get the error replacement has 127 rows, data has 400 (if I use a longer dataset).
I suppose this is because I am only returning rows with differences so the columns don't match up. How do I NA
the rows where there are no differences with setdiff so I can keep it in the original dataframe?