Hi, I'm looking for a function that takes a list and calculates a score based on how well "like attracts like". For example: list1 <- c(john, eric, steve, john, eric, scott, john) list2 <- c(john, john, john, eric, eric, steve, scott) score(list1) < score(list2) Both lists are composed of the same names and frequency of each name. Not sure how else to put it. I am relatively new to R. Have tried the modularity function, but can't seem to get it to work for this purpose. Any help is appreciated. Steve [[alternative HTML version deleted]]
What would the calculated score be for the example you give? Jean On Wed, Oct 30, 2013 at 7:03 AM, Stevan Lauriault < stevan.lauriault@gmail.com> wrote:> Hi, > > I'm looking for a function that takes a list and calculates a score based > on > how well "like attracts like". > For example: > > list1 <- c(john, eric, steve, john, eric, scott, john) > list2 <- c(john, john, john, eric, eric, steve, scott) > > score(list1) < score(list2) > > Both lists are composed of the same names and frequency of each > name. > > Not sure how else to put it. I am relatively new to R. Have tried the > modularity function, but can't seem to get it to work for this purpose. > > > Any help is appreciated. > > Steve > > [[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. >[[alternative HTML version deleted]]
You should cc r-help on all correspondence so everyone can follow the thread. Clearly I'm missing something. Perhaps others are, too. I don't know what you mean by "a score based on the co-localization of names" unless you give an example. Jean On Wed, Oct 30, 2013 at 10:34 AM, Stevan Lauriault < stevan.lauriault@gmail.com> wrote:> It would depend on the algorithm. Which is why I'm writing. I'm asking > if anyone knows of a preexisting algorithm that would calculate a score > based on the co-localization of names. > > S > > > > > > On Wed, Oct 30, 2013 at 10:56 AM, Adams, Jean <jvadams@usgs.gov> wrote: > >> What would the calculated score be for the example you give? >> >> Jean >> >> >> On Wed, Oct 30, 2013 at 7:03 AM, Stevan Lauriault < >> stevan.lauriault@gmail.com> wrote: >> >>> Hi, >>> >>> I'm looking for a function that takes a list and calculates a score >>> based on >>> how well "like attracts like". >>> For example: >>> >>> list1 <- c(john, eric, steve, john, eric, scott, john) >>> list2 <- c(john, john, john, eric, eric, steve, scott) >>> >>> score(list1) < score(list2) >>> >>> Both lists are composed of the same names and frequency of each >>> name. >>> >>> Not sure how else to put it. I am relatively new to R. Have tried the >>> modularity function, but can't seem to get it to work for this purpose. >>> >>> >>> Any help is appreciated. >>> >>> Steve >>> >>> [[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. >>> >> >> >[[alternative HTML version deleted]]
On 10/30/2013 11:03 PM, Stevan Lauriault wrote:> Hi, > > I'm looking for a function that takes a list and calculates a score based on > how well "like attracts like". > For example: > > list1<- c(john, eric, steve, john, eric, scott, john) > list2<- c(john, john, john, eric, eric, steve, scott) > > score(list1)< score(list2) > > Both lists are composed of the same names and frequency of each > name. > > Not sure how else to put it. I am relatively new to R. Have tried the > modularity function, but can't seem to get it to work for this purpose. > >Hi Steve, My first guess would be a distance function. Something like the variance of the indices of the various names: by(1:length(list1),list1,var) by(1:length(list2),list2,var) How you will handle the NAs generated by single names is another matter. Jim
Hi, Check whether this works: vec1 <- c( 'eric', 'JOHN', 'eric', 'JOHN', 'steve', 'scott', 'steve', 'scott', 'JOHN', 'eric') vec2 <- c( 'eric', 'JOHN', 'eric', 'eric', 'JOHN', 'JOHN', 'steve', 'steve', 'scott', 'scott') vec3 <- c( 'eric', 'eric', 'JOHN', 'eric', 'JOHN', 'JOHN', 'steve', 'steve', 'scott', 'scott') vec4 <- c( 'eric', 'eric', 'JOHN', 'eric', 'JOHN', 'steve', 'steve', 'scott', 'scott','JOHN') vec5 <- c('JOHN', 'JOHN', 'eric', 'eric', 'JOHN', 'eric', 'steve', 'steve', 'scott', 'scott') vec6 <- c( 'eric', 'eric',? 'eric', 'JOHN','JOHN', 'JOHN', 'steve', 'steve','scott', 'scott') vec7 <- c( 'eric', 'eric',? 'eric', 'JOHN','JOHN', 'JOHN', 'steve', 'scott', 'scott', 'steve') fun1 <- function(vec) { ?sum(unlist(sapply(unique(vec),function(x) {x1 <- diff(which(vec %in% x)); ifelse(x1==1, 1, -x1)}),use.names=FALSE)) ?} A.K. I took a steve and put it at the end of the vector. ?score should be less as the steves are farther apart.> vec3 <- c( 'eric', 'eric', ?'eric', 'JOHN','JOHN', 'JOHN', 'steve', 'steve','scott', 'scott') > sum(diff(vec3[-1]!=vec3[-length(vec3)])) + ?sum(vec3[-1]== vec3[-length(vec3)])[1] 6> vec4 <- c( 'eric', 'eric', ?'eric', 'JOHN','JOHN', 'JOHN', 'steve', 'scott', 'scott', 'steve') > sum(diff(vec4[-1]!=vec4[-length(vec4)])) + ?sum(vec4[-1]== vec4[-length(vec4)])[1] 6 S