if(length(names(v)[v>1])==0) {
numerator <- 0
} else {
distances.nearest.neighbors <- vector(length=sum(v[v>1])) # define a vector in which the minimal distances will be collected
position <- 0 # set a position at which to store the current minimal distance
for (i in names(v)[v>1]) { # loop over all corpus parts
current.corpus.part <- corpus[corpus.parts==as.numeric(i)] # look only at the i-th corpus part
current.element.positions <- which(current.corpus.part==element) # determine the locations of the element in this part
# create a vector that contains all positions of the element in question and that is
# prefixed by a number whose diff with the first position gives the length of the corpus part
# suffixed by a huge number so that the minimum distance of the last occurrence can only be to the preceding element
difference.builder <- c((current.element.positions[1]-length(current.corpus.part)), current.element.positions, 2*length(current.corpus.part))
for (j in 1:(length(difference.builder)-2)) { # loop over this vector
position <- position+1 # increment the position at which to store the current minimal distance
distances.nearest.neighbors[position] <- min(diff(difference.builder[j:(j+2)])) # determine the minimal distance and store it
} # end of for: loop over this vector
} # end of for: loop over all corpus parts
numerator <- sum(1/distances.nearest.neighbors)/length(distances.nearest.neighbors) # Washtell, p.c. 7/29/2008
}
values[["Washtell's Self Dispersion"]] <- numerator/denominatorCool, thanks a lot!
STG
--
Stefan Th. Gries
----------------------------------
Univ. of California, Santa Barbara
http://tinyurl.com/stgries
----------------------------------
--
You received this message because you are subscribed to the Google Groups "CorpLing with R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to corpling-with...@googlegroups.com.
To post to this group, send email to corplin...@googlegroups.com.
Visit this group at http://groups.google.com/group/corpling-with-r.
For more options, visit https://groups.google.com/d/optout.