Federico Calboli
2015-Aug-06 10:25 UTC
[R] testing whether two character vectors contain (the same) items in the same order
Hi All, let?s assume I have a vector of letters drawn only once from the alphabet: x = sample(letters, 15, replace = F) x [1] "z" "t" "g" "l" "u" "d" "w" "x" "a" "q" "k" "j" "f" "n" ?v" y = x[c(1:7,9:8, 10:12, 14, 15, 13)] I would now like to test how good a match y is for x. Obviously I can transform the letters in numbers and use a rank test, but I was left wondering whether this is the only solution and whether there are more appropriate solutions that are already implemented in R (I am not going to reinvent the wheel if I can avoid it). BW F -- Federico Calboli Ecological Genetics Research Unit Department of Biosciences PO Box 65 (Biocenter 3, Viikinkaari 1) FIN-00014 University of Helsinki Finland federico.calboli at helsinki.fi
Bert Gunter
2015-Aug-06 12:40 UTC
[R] testing whether two character vectors contain (the same) items in the same order
Define "goodness of match" . For exact matches, see ?"==" , all.equal, etc. Bert On Thursday, August 6, 2015, Federico Calboli <federico.calboli at helsinki.fi> wrote:> Hi All, > > let?s assume I have a vector of letters drawn only once from the alphabet: > > x = sample(letters, 15, replace = F) > x > [1] "z" "t" "g" "l" "u" "d" "w" "x" "a" "q" "k" "j" "f" "n" ?v" > > y = x[c(1:7,9:8, 10:12, 14, 15, 13)] > > I would now like to test how good a match y is for x. Obviously I can > transform the letters in numbers and use a rank test, but I was left > wondering whether this is the only solution and whether there are more > appropriate solutions that are already implemented in R (I am not going to > reinvent the wheel if I can avoid it). > > BW > > F > > > -- > Federico Calboli > Ecological Genetics Research Unit > Department of Biosciences > PO Box 65 (Biocenter 3, Viikinkaari 1) > FIN-00014 University of Helsinki > Finland > > federico.calboli at helsinki.fi <javascript:;> > > ______________________________________________ > R-help at r-project.org <javascript:;> mailing list -- To UNSUBSCRIBE and > more, see > 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.-- Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll [[alternative HTML version deleted]]
Federico Calboli
2015-Aug-06 13:51 UTC
[R] testing whether two character vectors contain (the same) items in the same order
> On 6 Aug 2015, at 15:40, Bert Gunter <bgunter.4567 at gmail.com> wrote: > > Define "goodness of match" . For exact matches, see ?"==" , all.equal, etc.Fair point. I would define it as a number that tells me how likely it is that the same (noisy) process produced both lists. BW F> > Bert > > On Thursday, August 6, 2015, Federico Calboli <federico.calboli at helsinki.fi> wrote: > Hi All, > > let?s assume I have a vector of letters drawn only once from the alphabet: > > x = sample(letters, 15, replace = F) > x > [1] "z" "t" "g" "l" "u" "d" "w" "x" "a" "q" "k" "j" "f" "n" ?v" > > y = x[c(1:7,9:8, 10:12, 14, 15, 13)] > > I would now like to test how good a match y is for x. Obviously I can transform the letters in numbers and use a rank test, but I was left wondering whether this is the only solution and whether there are more appropriate solutions that are already implemented in R (I am not going to reinvent the wheel if I can avoid it). > > BW > > F > > > -- > Federico Calboli > Ecological Genetics Research Unit > Department of Biosciences > PO Box 65 (Biocenter 3, Viikinkaari 1) > FIN-00014 University of Helsinki > Finland > > federico.calboli at helsinki.fi > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > > > -- > Bert Gunter > > "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." > -- Clifford Stoll >-- Federico Calboli Ecological Genetics Research Unit Department of Biosciences PO Box 65 (Biocenter 3, Viikinkaari 1) FIN-00014 University of Helsinki Finland federico.calboli at helsinki.fi
Robert Baer
2015-Aug-08 17:50 UTC
[R] testing whether two character vectors contain (the same) items in the same order
On 8/6/2015 5:25 AM, Federico Calboli wrote:> Hi All, > > let?s assume I have a vector of letters drawn only once from the alphabet: > > x = sample(letters, 15, replace = F) > x > [1] "z" "t" "g" "l" "u" "d" "w" "x" "a" "q" "k" "j" "f" "n" ?v" > > y = x[c(1:7,9:8, 10:12, 14, 15, 13)] > > I would now like to test how good a match y is for x. Obviously I can transform the letters in numbers and use a rank test, but I was left wondering whether this is the only solution and whether there are more appropriate solutions that are already implemented in R (I am not going to reinvent the wheel if I can avoid it). > > BW > > FPerhaps install.packages("stringdist") help(package = 'stringdist')> > -- > Federico Calboli > Ecological Genetics Research Unit > Department of Biosciences > PO Box 65 (Biocenter 3, Viikinkaari 1) > FIN-00014 University of Helsinki > Finland > > federico.calboli at helsinki.fi > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Robert Baer
2015-Aug-08 18:21 UTC
[R] testing whether two character vectors contain (the same) items in the same order
And I probably should have included this link: http://journal.r-project.org/archive/2014-1/loo.pdf On 8/8/2015 12:50 PM, Robert Baer wrote:> > > On 8/6/2015 5:25 AM, Federico Calboli wrote: >> Hi All, >> >> let?s assume I have a vector of letters drawn only once from the >> alphabet: >> >> x = sample(letters, 15, replace = F) >> x >> [1] "z" "t" "g" "l" "u" "d" "w" "x" "a" "q" "k" "j" "f" "n" ?v" >> >> y = x[c(1:7,9:8, 10:12, 14, 15, 13)] >> >> I would now like to test how good a match y is for x. Obviously I >> can transform the letters in numbers and use a rank test, but I was >> left wondering whether this is the only solution and whether there >> are more appropriate solutions that are already implemented in R (I >> am not going to reinvent the wheel if I can avoid it). >> >> BW >> >> F > Perhaps > install.packages("stringdist") > help(package = 'stringdist') > > > > > >> >> -- >> Federico Calboli >> Ecological Genetics Research Unit >> Department of Biosciences >> PO Box 65 (Biocenter 3, Viikinkaari 1) >> FIN-00014 University of Helsinki >> Finland >> >> federico.calboli at helsinki.fi >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. >