- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个关于组合的问题,但在相当复杂的情况下,我还没有找到任何帮助。我正在尝试找到一种方法来报告数据集中列的所有可能组合。
有关土地变化文献调查的数据报告,并指出每篇文章中报告了哪些近因和潜在驱动因素。因此,行表示单个文章,而列表示所有接近和潜在的驱动程序。有六种直接驱动因素和五种潜在驱动因素。对于每篇文章,在该文章中标识的驱动程序的列中放置 1,而在非驱动程序的列中放置 0。该表大致如下所示:
key | d1 | d2 |...| d6 | i1 |...| i5 |
--------------------------------------
A1 | 1 | 0 |...| 1 | 1 |...| 0 |
A2 | 0 | 1 |...| 0 | 0 |...| 1 |
其中文章 A1 将 d1 和 d6 标识为直接驱动程序,将 i1 标识为间接驱动程序等。
我想做的是找出报告直接驱动因素、间接驱动因素以及直接和间接驱动因素的所有可能组合的文章数量。因此,例如,有多少文章标识了 d1、d2 和 i1;有多少人识别出 d1、d2 和 i2;等等?我的学生在 Excel 文件中有表格,我在想也许 Calc 或 Base 可能有一个功能来自动化这个过程。有人知道我该怎么做吗?
谢谢!
最佳答案
我最终放弃并采用了蛮力方法。我将表导出为文本并将其拉入 MySQL,然后使用 bash 脚本遍历选项。如果其他人有类似的问题,这里是 bash 脚本:
# Generate array containing factors
faclis1=( d_inf d_com d_inm d_ind d_agr d_bos i_dem i_eco i_tec i_pol i_cul );
#faclis=( "d_inf" "d_com" "d_inm" );
a=0
#echo ${faclis[@]};
# Remove output file if exists
if [ -e permcounts.txt ];
then
rm permcounts.txt;
fi;
# Cycle through list of factors
for f1 in ${faclis1[@]};
do
# only proceed if factor not null
if [ ${f1} ];
then
# print remaining array just to be sure
echo "factor list is ${faclis1[@]}";
#echo ${faclis[@]};
echo "Now on factor ${f1}";
echo "FACTOR ${f1}" >> permcounts.txt;
mysql -u harvey -pdavid -e "select count(clave) from genfact where \
${f1} = 1;" metamorelia >> permcounts.txt;
# create sub array without current factor, 2 factors
faclis2=( ${faclis1[@]/${f1}/} );
#set sub-counter
b=0
#echo "${faclis2[@]}";
# loop through sub array, two factors
for f2 in ${faclis2[@]};
do
if [ ${f2} ] && \
[ "${f1}" != "${f2}" ];
then
echo "FACTOR ${f1} \
AND ${f2}" >> permcounts.txt;
mysql -u harvey -pdavid -e "select count(clave) from genfact where \
${f1} = 1 and \
${f2} = 1;" metamorelia >> permcounts.txt;
# next sub-array
faclis3=( ${faclis2[@]//${f2}} );
c=0
#echo "${faclis3[@]}";
# loop through sub-array
for f3 in ${faclis3[@]};
do
if [ ${f3} ] && \
[ "${f1}" != "${f3}" ] && \
[ "${f2}" != "${f3}" ];
then
echo "FACTOR ${f1} \
AND ${f2} \
AND ${f3}" >> permcounts.txt;
mysql -u harvey -pdavid -e "select count(clave) from genfact where \
${f1} = 1 and \
${f2} = 1 and \
${f3} = 1;" metamorelia >> permcounts.txt;
# next sub-array
faclis4=( ${faclis3[@]//${f3}} );
d=0
#echo "${faclis4[@]}";
# loop through sub-array
for f4 in ${faclis4[@]};
do
if [ ${f4} ] && \
[ "${f1}" != "${f4}" ] && \
[ "${f2}" != "${f4}" ] && \
[ "${f3}" != "${f4}" ];
then
echo "FACTOR ${f1} \
AND ${f2} \
AND ${f3} \
AND ${f4}" >> permcounts.txt;
mysql -u harvey -pdavid -e "select count(clave) from genfact where \
${f1} = 1 and \
${f2} = 1 and \
${f3} = 1 and \
${f4} = 1;" metamorelia >> permcounts.txt;
# next sub-array
faclis5=( ${faclis4[@]//${f4}} );
e=0
#echo "${faclis5[@]}";
# loop through sub-array
for f5 in ${faclis5[@]};
do
if [ ${f5} ] && \
[ "${f1}" != "${f5}" ] && \
[ "${f2}" != "${f5}" ] && \
[ "${f3}" != "${f5}" ] && \
[ "${f4}" != "${f5}" ];
then
echo "FACTOR ${f1} \
AND ${f2} \
AND ${f3} \
AND ${f4} \
AND ${f5}" >> permcounts.txt;
mysql -u harvey -pdavid -e "select count(clave) from genfact where \
${f1} = 1 and \
${f2} = 1 and \
${f3} = 1 and \
${f4} = 1 and \
${f5} = 1;" metamorelia >> permcounts.txt;
# next sub-array
faclis6=( ${faclis5[@]//${f5}} );
f=0
#echo "${faclis6[@]}";
# loop through sub-array
for f6 in ${faclis6[@]};
do
if [ ${f6} ] && \
[ "${f1}" != "${f6}" ] && \
[ "${f2}" != "${f6}" ] && \
[ "${f3}" != "${f6}" ] && \
[ "${f4}" != "${f6}" ] && \
[ "${f5}" != "${f6}" ];
then
echo "FACTOR ${f1} \
AND ${f2} \
AND ${f3} \
AND ${f4} \
AND ${f5} \
AND ${f6}" >> permcounts.txt;
mysql -u harvey -pdavid -e "select count(clave) from genfact where \
${f1} = 1 and \
${f2} = 1 and \
${f3} = 1 and \
${f4} = 1 and \
${f5} = 1 and \
${f6} = 1;" metamorelia >> permcounts.txt;
# next sub-array
faclis7=( ${faclis6[@]//${f6}} );
g=0
#echo "${faclis7[@]}";
# loop through sub-array
for f7 in ${faclis7[@]};
do
if [ ${f7} ] && \
[ "${f1}" != "${f7}" ] && \
[ "${f2}" != "${f7}" ] && \
[ "${f3}" != "${f7}" ] && \
[ "${f4}" != "${f7}" ] && \
[ "${f5}" != "${f7}" ] && \
[ "${f6}" != "${f7}" ];
then
echo "FACTOR ${f1} \
AND ${f2} \
AND ${f3} \
AND ${f4} \
AND ${f5} \
AND ${f6} \
AND ${f7}" >> permcounts.txt;
mysql -u harvey -pdavid -e "select count(clave) from genfact where \
${f1} = 1 and \
${f2} = 1 and \
${f3} = 1 and \
${f4} = 1 and \
${f5} = 1 and \
${f6} = 1 and \
${f7} = 1;" metamorelia >> permcounts.txt;
# next sub-array
faclis8=( ${faclis7[@]//${f7}} );
h=0
#echo "${faclis8[@]}";
# loop through sub-array
for f8 in ${faclis8[@]};
do
if [ ${f8} ] && \
[ "${f1}" != "${f8}" ] && \
[ "${f2}" != "${f8}" ] && \
[ "${f3}" != "${f8}" ] && \
[ "${f4}" != "${f8}" ] && \
[ "${f5}" != "${f8}" ] && \
[ "${f6}" != "${f8}" ] && \
[ "${f7}" != "${f8}" ];
then
echo "FACTOR ${f1} \
AND ${f2} \
AND ${f3} \
AND ${f4} \
AND ${f5} \
AND ${f6} \
AND ${f7} \
AND ${f8}" >> permcounts.txt;
mysql -u harvey -pdavid -e "select count(clave) from genfact where \
${f1} = 1 and \
${f2} = 1 and \
${f3} = 1 and \
${f4} = 1 and \
${f5} = 1 and \
${f6} = 1 and \
${f7} = 1 and \
${f8} = 1;" metamorelia >> permcounts.txt;
# next sub-array
faclis9=( ${faclis8[@]//${f8}} );
i=0
#echo "${faclis9[@]}";
# loop through sub-array
for f9 in ${faclis9[@]};
do
if [ ${f9} ] && \
[ "${f1}" != "${f9}" ] && \
[ "${f2}" != "${f9}" ] && \
[ "${f3}" != "${f9}" ] && \
[ "${f4}" != "${f9}" ] && \
[ "${f5}" != "${f9}" ] && \
[ "${f6}" != "${f9}" ] && \
[ "${f7}" != "${f9}" ] && \
[ "${f8}" != "${f9}" ];
then
echo "FACTOR ${f1} \
AND ${f2} \
AND ${f3} \
AND ${f4} \
AND ${f5} \
AND ${f6} \
AND ${f7} \
AND ${f8} \
AND ${f9}" >> permcounts.txt;
mysql -u harvey -pdavid -e "select count(clave) from genfact where \
${f1} = 1 and \
${f2} = 1 and \
${f3} = 1 and \
${f4} = 1 and \
${f5} = 1 and \
${f6} = 1 and \
${f7} = 1 and \
${f8} = 1 and \
${f9} = 1;" metamorelia >> permcounts.txt;
# next sub-array
faclis10=( ${faclis9[@]//${f9}} );
j=0
#echo "${faclis10[@]}";
# loop through sub-array
for f10 in ${faclis10[@]};
do
if [ ${f10} ] && \
[ "${f1}" != "${f10}" ] && \
[ "${f2}" != "${f10}" ] && \
[ "${f3}" != "${f10}" ] && \
[ "${f4}" != "${f10}" ] && \
[ "${f5}" != "${f10}" ] && \
[ "${f6}" != "${f10}" ] && \
[ "${f7}" != "${f10}" ] && \
[ "${f8}" != "${f10}" ] && \
[ "${f9}" != "${f10}" ];
then
echo "FACTOR ${f1} \
AND ${f2} \
AND ${f3} \
AND ${f4} \
AND ${f5} \
AND ${f6} \
AND ${f7} \
AND ${f8} \
AND ${f9} \
AND ${f10}" >> permcounts.txt;
mysql -u harvey -pdavid -e "select count(clave) from genfact where \
${f1} = 1 and \
${f2} = 1 and \
${f3} = 1 and \
${f4} = 1 and \
${f5} = 1 and \
${f6} = 1 and \
${f7} = 1 and \
${f8} = 1 and \
${f9} = 1 and \
${f10} = 1;" metamorelia >> permcounts.txt;
# next sub-array
faclis11=( ${faclis10[@]//${f10}} );
k=0
#echo "${faclis11[@]}";
# loop through sub-array
for f11 in ${faclis11[@]};
do
if [ ${f11} ] && \
[ "${f1}" != "${f11}" ] && \
[ "${f2}" != "${f11}" ] && \
[ "${f3}" != "${f11}" ] && \
[ "${f4}" != "${f11}" ] && \
[ "${f5}" != "${f11}" ] && \
[ "${f6}" != "${f11}" ] && \
[ "${f7}" != "${f11}" ] && \
[ "${f8}" != "${f11}" ] && \
[ "${f9}" != "${f11}" ] && \
[ "${f10}" != "${f11}" ];
then
echo "FACTOR ${f1} \
AND ${f2} \
AND ${f3} \
AND ${f4} \
AND ${f5} \
AND ${f6} \
AND ${f7} \
AND ${f8} \
AND ${f9} \
AND ${f10} \
AND ${f11}" >> permcounts.txt;
mysql -u harvey -pdavid -e "select count(clave) from genfact where \
${f1} = 1 and \
${f2} = 1 and \
${f3} = 1 and \
${f4} = 1 and \
${f5} = 1 and \
${f6} = 1 and \
${f7} = 1 and \
${f8} = 1 and \
${f9} = 1 and \
${f10} = 1 and \
${f11} = 1;" metamorelia >> permcounts.txt;
unset faclis11[k];
k=$((${k} + 1));
fi;
done;
unset faclis10[j];
j=$((${j} + 1));
fi;
done;
unset faclis9[i];
i=$((${i} + 1));
fi;
done;
unset faclis8[h];
h=$((${h} + 1));
fi;
done;
unset faclis7[g];
g=$((${g} + 1));
fi;
done;
unset faclis6[f];
f=$((${f} + 1));
fi;
done;
unset faclis5[e];
e=$((${e} + 1));
fi;
done;
unset faclis4[d];
d=$((${d} + 1));
fi;
done;
unset faclis3[c];
c=$((${c} + 1));
fi;
done;
# Remove analyzed factors from vector
unset faclis2[b];
b=$((${b} + 1));
fi;
done;
# remove nth item from array (progressively remove one item)
unset faclis1[a];
# increment n for next round
a=$((${a} + 1));
echo ${n};
fi;
done;
这个脚本有点低效,因为我认为我包含了很多不必要的操作,但它完成了工作。 (我认为确实如此。我的学生将不得不浏览输出文件以确保一切都在那里。)
关于mysql - 报告所有可能的列组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46064319/
我正在 csv 上使用 hadoop 来分析一些数据。我使用sql/mysql(不确定)来分析数据,现在陷入了僵局。 我花了好几个小时在谷歌上搜索,却没有找到任何相关的东西。我需要一个查询,在该查询中
我正在为 Bootstrap 网格布局的“简单”任务而苦苦挣扎。我希望在大视口(viewport)上有 4 列,然后在中型设备上有 2 列,最后在较小的设备上只有 1 列。 当我测试我的代码片段时,似
对于这个令人困惑的标题,我深表歉意,我想不出这个问题的正确措辞。相反,我只会给你背景信息和目标: 这是在一个表中,一个人可能有也可能没有多行数据,这些行可能包含相同的 activity_id 值,也可
具有 3 列的数据库表 - A int , B int , C int 我的问题是: 如何使用 Sequelize 结果找到 A > B + C const countTasks = await Ta
我在通过以下功能编写此查询时遇到问题: 首先按第 2 列 DESC 排序,然后从“不同的第 1 列”中选择 只有 Column1 是 DISTINCT 此查询没有帮助,因为它首先从第 1 列中进行选择
使用 Bootstrap 非常有趣和有帮助,目前我在创建以下需求时遇到问题。 “使用 bootstrap 在桌面上有 4 列,在平板电脑上有 2 列,在移动设备上有 1 列”谁能告诉我正确的结构 最佳
我是 R 新手,正在问一个非常基本的问题。当然,我在尝试从所提供的示例中获取指导的同时做了功课here和 here ,但无法在我的案例中实现这个想法,即可能是由于我的问题中的比较维度更大。 我的实
通常我会使用 R 并执行 merge.by,但这个文件似乎太大了,部门中的任何一台计算机都无法处理它! (任何从事遗传学工作的人的附加信息)本质上,插补似乎删除了 snp ID 的 rs 数字,我只剩
我有一个 df , delta1 delta2 0 -1 2 0 -1 0 0 0 我想知道如何分配 delt
您好,我想知道是否可以执行以下操作。显然,我已经尝试在 phpMyAdmin 中运行它,但出现错误。也许还有另一种方式来编写此查询。 SELECT * FROM eat_eat_restaurants
我有 2 个列表(标题和数据值)。我想要将数据值列 1 匹配并替换为头文件列 1,以获得与 dataValue 列 1 和标题值列 2 匹配的值 头文件 TotalLoad,M0001001 Hois
我有两个不同长度的文件,file2 是一个很大的引用文件,我从中提取文件 1 的数据。 我有一行 awk,我通常会对其进行调整以在我的文件中进行查找和替换,但它总是在同一列中进行查找和替换。 所以对于
假设我有两个表,如下所示。 create table contract( c_ID number(1) primary key, c_name varchar2(50) not
我有一个带有 varchar 列的 H2 表,其检查约束定义如下: CONSTRAINT my_constraint CHECK (varchar_field <> '') 以下插入语句失败,但当我删
这是最少量的代码,可以清楚地说明我的问题: One Two Three 前 2 个 div 应该是 2 个左列。第三个应该占据页面的其余部分。最后,我将添加选项来隐藏和
在 Azure 中的 Log Analytics 中,我为 VM Heartbeat 选择一个预定义查询,我在编辑器中运行查询正常,但当我去创建警报时,我不断收到警报“查询未返回 TimeGenera
在 Azure 中的 Log Analytics 中,我为 VM Heartbeat 选择一个预定义查询,我在编辑器中运行查询正常,但当我去创建警报时,我不断收到警报“查询未返回 TimeGenera
今天我开始使用 JexcelApi 并遇到了这个:当您尝试从特定位置获取元素时,不是像您通常期望的那样使用sheet.getCell(row,col),而是使用sheet.getCell(col,ro
我有一个包含 28 列的数据库。第一列是代码,第二列是名称,其余是值。 public void displayData() { con.Open(); MySqlDataAdapter
我很沮丧:每当我缩小这个网页时,一切都变得一团糟。我如何将网页居中,以便我可以缩小并且元素不会被错误定位。 (它应该是 2 列,但所有内容都合并为 1)我试过 但由于某种原因,这不起作用。 www.o
我是一名优秀的程序员,十分优秀!