2017-09-05 7 views
1

일반적으로 조합에 관한 질문이 있지만, 아직 어떤 도움도 찾을 수없는 상당히 복잡한 상황입니다. 데이터 집합에서 의 가능한 모든 조합을보고하는 방법을 찾으려고합니다.가능한 모든 조합의 조합을보고하십시오.

자료는 토지 변화에 대한 문헌 조사에 대해보고하고 각 기사에서보고 된 근거리 및 근본적인 운전자를 나타냅니다. 따라서 행은 개별 아티클을 나타내며 열은 모두 인접한 기본 드라이버를 나타냅니다. 근접 운전자에는 6 가지 유형이 있고 기본 운전자에는 5 가지 유형이 있습니다. 각 기사의 경우 해당 기사에서 식별 된 드라이버의 열에 1이 배치되고 드라이버의 열에는 0이 배치됩니다. 표는 대략 그래서 다음과 같습니다

key | d1 | d2 |...| d6 | i1 |...| i5 | 
-------------------------------------- 
A1 | 1 | 0 |...| 1 | 1 |...| 0 | 
A2 | 0 | 1 |...| 0 | 0 |...| 1 | 
기사 A1 등 (D1) 및 간접 드라이버로 직접 드라이버와 I1 같은 D6를 식별

내가하고 싶은 무엇

기사의 수를 알 수있다 직접 운전자, 간접 운전자, 직접 및 간접 운전자의 가능한 모든 조합을보고합니다. 예를 들어 얼마나 많은 기사가 d1, d2 및 i1을 식별하는지; 얼마나 많은 사람들이 d1, d2 및 i2를 식별 하는가? 등등? 학생들은 Excel 파일에 테이블을 가지고 있습니다. 아마도 Calc 또는 Base에 프로세스를 자동화하는 기능이 있다고 생각했습니다. 나는 이것을 할 수있는 방법에 대해 누구나 생각을 가지고 있습니까?

감사합니다.

+0

2^11 조합을 모두 식별하고 각각의 개수가 몇 개인 지 계산하고 싶습니까? 그것은 2048 개의 다른 조합입니다. –

+0

그래서 나는 그 과정을 단순화하기를 바랬다. 아이디어는 문학에서 가장 자주 발생하는 운전자 조합을 파악하는 것입니다. – Napoletano

+0

작은 UDF (또는 2 진수를 연결)를 사용하여 드라이버를 조건부 문자열로 결합하십시오. 그런 다음 피벗 테이블을 사용하여 각 조합 문자열의 수를 계산하십시오. – MacroMarc

답변

0

나는 마침내 포기하고 무차별 대입 방식으로 갔다. 테이블을 텍스트로 내보내고 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; 

이 스크립트는 점에서 다소 비효율적이다 나는 불필요한 작업을 많이 포함되어 있다고 생각하지만, 그것은 작업이 완료되었다. (내 생각에 학생들은 출력 파일을 탐색하여 모든 것이 있는지 확인해야합니다.)