Would: ?merge Work for you ?
----------------Contact Details:------------------------------------------------------- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- On Sun, Apr 18, 2010 at 7:30 PM, Laura Ferrero-Miliani <laur...@gmail.com>wrote: > Dear very helpful friends, > > It is Sunday, there is no air traffic in Europe, what better to do > than try and learn me some more R. > I have the following example: > > owner <- c(1:4) > animal <- c("cat", "dog", "cat", "dog") > char.1 <- c("fluffy", "playful", "mean", "stupid") > food <- c("cat food", "left-overs", "cat food", "dog food") > char.2 <- c("lazy", "destructive", "antisocial", "goofy") > color <- c("white", "brown", "black", "black") > char.3 <- c("fat", "tiny", "evil", "big") > age <- c(16, 2, 5, 10) > > pet.data <- data.frame(owner, animal, char.1, food, char.2, > color, char.3, age) > > animal <- c("cat", "dog") > v1 <- c("fluffy", "big") > v2 <- c("fat", "stupid") > > pet.key <- data.frame(animal, v1, v2) > > > Now I would like to compare my pet.key to my pet.data and add a > variable to pet.data with that result. > So for each "cat" in pet.data, char.1, char.2 and char.3 should > contain "fluffy" AND "fat" for a complete match, or "fluffy" OR "fat" > for a partial match, and so on. > > I don't know where to start. I *think* I should be using %in%, but I > don't know how to build the expression so it works (so far I have > tried and have gotten from lists to a weird array as a result!) > > btw, what if my data and my key contains repeated values e.g. > > animal v1 v2 > cat fluffy fluffy > > > Any suggestions? > > > Thanks in advance, > > Laura > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.