Hi, I am very happy. My problems are solved without one little thing: (Iske <- matrix(c(1, 1, 1, 2, 2, 2, 1, 1, 1, 5, 1, 2, 2, 2, 1, 1, 1, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 2), ncol = 5)) #My Matrix Iske<- Iske+33 #I want see the letters (Iske.char<-apply(Iske, 1, function(x) rawToChar(as.raw(x)))) #Numbers to Char LD <- function(s1, s2){ require(vwr) s1 = as.character(s1) s2 = as.character(s2) t(sapply(s1, levenshtein.distance, s2)) } Iske.levens<-(LD(Iske.char,Iske.char)) #Calculate the Levenshtein-Distanz The result: !"#$% !"#$% !"#$% "!#$% .... !"#$% 0 0 0 !"#$% 0 0 0 !"#$% 0 0 0 . . . It is all beautiful. But is there a simple way to change the column/row-name to the original from the Matrix Iske? Thanks a lot for the help yesterday. It was a big step in my life :-)
I'm not sure I follow: the matrix Iske doesn't have row or column names....though if you perhaps mean you want to use the pasted together rows as names on the distance matrix rather than the converted characters, this will do it: Iske.rows <- apply(Iske, 1, paste, collapse = "") # Perhaps subtract out the 33 you added in dimnames(Iske.levens) <- list(Iske.rows, Iske.rows) On Fri, Oct 21, 2011 at 1:57 AM, J?rg Reuter <joerg at reuter.at> wrote:> Hi, > I am very happy. My problems are solved without one little thing: > > (Iske <- matrix(c(1, 1, 1, 2, 2, 2, 1, 1, 1, 5, 1, 2, 2, 2, 1, 1, 1, > 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 4, 4, 4, 4, 2, > 2, 2, 2, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 2), ncol = 5)) #My Matrix > > Iske<- Iske+33 #I want see the letters > > (Iske.char<-apply(Iske, 1, function(x) rawToChar(as.raw(x)))) #Numbers to Char > LD <- function(s1, s2){ > ? ?require(vwr) > ? ?s1 = as.character(s1) > ? ?s2 = as.character(s2) > ? ?t(sapply(s1, levenshtein.distance, s2)) > } > Iske.levens<-(LD(Iske.char,Iske.char)) #Calculate the Levenshtein-Distanz > > The result: > !"#$% !"#$% !"#$% "!#$% .... > !"#$% ? ? 0 ? ? 0 ? ? 0 > !"#$% ? ? 0 ? ? 0 ? ? 0 > !"#$% ? ? 0 ? ? 0 ? ? 0 > . > . > . > It is all beautiful. But is there a simple way to change the > column/row-name to the original from the Matrix Iske? > > Thanks a lot for the help yesterday. It was a big step in my life :-) > > ______________________________________________ > R-help at 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. >
On Oct 21, 2011, at 1:57 AM, J?rg Reuter wrote:> Hi, > I am very happy. My problems are solved without one little thing: > > (Iske <- matrix(c(1, 1, 1, 2, 2, 2, 1, 1, 1, 5, 1, 2, 2, 2, 1, 1, 1, > 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 4, 4, 4, 4, 2, > 2, 2, 2, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 2), ncol = 5)) #My MatrixFirst transform to characters. (Using raw type seems failure-prone): Iltrs <- c(letters, LETTERS)[Iske] Then work with that. (No testing in absence of the levenshtein.distance function definition or package location.)> > Iske<- Iske+33 #I want see the letters > > (Iske.char<-apply(Iske, 1, function(x) rawToChar(as.raw(x)))) > #Numbers to Char > LD <- function(s1, s2){ > require(vwr) > s1 = as.character(s1) > s2 = as.character(s2) > t(sapply(s1, levenshtein.distance, s2)) > } > Iske.levens<-(LD(Iske.char,Iske.char)) #Calculate the Levenshtein- > Distanz > > The result: > !"#$% !"#$% !"#$% "!#$% .... > !"#$% 0 0 0 > !"#$% 0 0 0 > !"#$% 0 0 0 > . > . > . > It is all beautiful. But is there a simple way to change the > column/row-name to the original from the Matrix Iske? > > Thanks a lot for the help yesterday. It was a big step in my life :-) > > ______________________________________________ > R-help at 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.David Winsemius, MD West Hartford, CT