hammingDist
Odległość Hamming'a:
hammingDist<-function(x,y){ if(length(x)!=1 | length(y)!=1) stop("x,y - not a single string!") if(nchar(x)!=nchar(y)) stop("x,y - not equal length!") tmpX<-strsplit(as.character(x),'')[[1]] tmpY<-strsplit(as.character(y),'')[[1]] res<-NULL for(i in 1:length(tmpX)){ res[i]<-tmpX[i]!=tmpY[i] } return(sum(res)) }
Created by Pretty R at inside-R.org
hammingDist<-function(x,y){ if(length(x)!=1 | length(y)!=1) stop("x,y - not a single string!") if(nchar(x)!=nchar(y)) stop("x,y - not equal length!") tmpX<-strsplit(as.character(x),'')[[1]] tmpY<-strsplit(as.character(y),'')[[1]] res<-NULL for(i in 1:length(tmpX)){ res[i]<-tmpX[i]!=tmpY[i] } result<-list() result[['hammingDist']]<-sum(res) tmpX[res]<-"." result[['commonPattern']]<-paste(tmpX,sep="",collapse="") return(result) }
Created by Pretty R at inside-R.org
hammingDist<-function(x,y){ if(length(x)!=1 | length(y)!=1) stop("x,y - not a single string!") if(nchar(x)!=nchar(y)) stop(paste("x,y - not equal length!\n","x= ", nchar(x),"\ny= ",nchar(y),sep="")) tmpX<-strsplit(as.character(x),'')[[1]] tmpY<-strsplit(as.character(y),'')[[1]] res<-NULL for(i in 1:length(tmpX)){ res[i]<-tmpX[i]!=tmpY[i] } result<-list() result[['hammingDist']]<-sum(res) tmpX[res]<-"." result[['commonPattern']]<-paste(tmpX,sep="",collapse="") return(result) }
Jak R szuka i znajduje
Dla tych, którzy chcą lepiej poznać środowisko R w którym pracują polecam artykuł:
"How R Searches And Finds Stuff"
oraz
Wydano R 2.15.0
Opublikowano najnowszą wersję R'a 2.15.0.
Więcej na ten temat na R-bloggers.
Kod źródłowy można pobrać z:
« poprzednia strona |
Wyświetlanie wpisów 9-16 z 84 |
następna strona »