在谷歌小号preadsheet自定义函数:其中一组人,其他国家之间的分歧 [英] Custom function in Google Spreadsheet: disagreement between one person and rest of the group

查看:171
本文介绍了在谷歌小号preadsheet自定义函数:其中一组人,其他国家之间的分歧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算的调查受访者的分歧。

I need to calculate the disagreement between respondents of a survey.

第一步是计算两个受访者的分歧

The first step was to calculate the disagreement between two respondents

function disagree(DISAG, otherMember) { 
  return Math.abs(DISAG.localeCompare(otherMember));
}

第二步是计算一个受访者和所有其它的平均分歧。

The second step is to calculate the average disagreement between one respondent and all the others.

要以人工手动,我必须做的:

To to so manually, I have to do:

1/(N-1) * (disagree(DISAG, otherMember) + disagree(DISAG, othermember2)) etc

要尽量做到一步到位,我写了下面的功能,作为测试

To try to do it in one go, I wrote the following function, as a test

function TEST(DISAG) { 

 var otherMembers = ["No problem", "Can improve", "Can improve"]
 var indivDisag = []
 var sum = 0     

 for (var i in otherMembers) { 
  indivDisag[i] = DISAG.localeCompare(otherMembers[i])
 };

 for (var i in indivDisag) { 
  sum +=  Math.abs(indivDisag[i]); 
 };

  return sum / indivDisag.length

}

编辑:我原来的问题是由于一个错字。我现在得到在s preadsheet返回一个数字,但无论DISAG的值,这个数字是永远不变的。它必须是我正确地没有跨preT算术编码的功能时。

My original issue was due to a typo. I now get a number returned in the spreadsheet, but whatever the value of DISAG, the number is always the same. It must be that I didn't interpret the math correctly when coding the function.

数学是这样的:

d(i,j) = disagreement of an individual (i) with another (j).
if i == j, then d(i,j) = 0. if i != j then d(i,j) = 1

di = average agreement of one person with the rest of the group.

di = 1/(N-1) * SUM( d(i,j)*f(j) )

where N = number of people who answered the survey
and f(j) is a function of the different individual disagreements.

在纯英文:一个人的平均协议是她个人的协议,由组(N-1)

In plain English : the average agreement of one person is the result of the sum of her individual agreements divided by the number of pairs possible in the group (N-1).

感谢您的帮助。

推荐答案

分的情侣

我不链接谷歌脚本知道什么localCompare()是。
所以,如果你解决这个问题它会认为你已经附加了函数的对象。

I don't link google script knows what localCompare() is. So if you fix this it will think you have attached a function to an object.

因为它需要传递一个变量调试器将无法在你的函数运行。

The debugger won't run on your function because it expects to be passed a variable.

function TEST(DISAG) { 

在运行调试器,也不会知道什么是DISAG指的是。因此,当遇到它

When you run the debugger, it won't know what "DISAG" refers to. So when it encounters it in

indivDisag = DISAG.localCompare(otherMembers[i])

这将不知道该怎么办。

It won't know what to do.

您可以把它作为功能测试(在一个变量),用于调试。

You could include it as a variable within the function TEST(), for debugging purposes.

这篇关于在谷歌小号preadsheet自定义函数:其中一组人,其他国家之间的分歧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆