uspTukubaiコマンドに関する様々な資料がここにあります。

 

 

魂内検索

DOCUMENTS

COMMAND

FORUM

UEC DOCS

VIDEO

 

Alphabetical list

(Video materials in preparation)

proportion(USP)

Name

proportion : Returns a proportion

Synopsis

Usage   : proportion [key=<key>] val=<val> <file>

Option  : -<p>

          +<n>h

          --first

          --last

          --max

          --min

          --auto

Version : Wed Sep 19 13:56:03 JST 2018

Edition : 1

Description

Within a group of records (rows) in <file> (or stdin) that have the

same value in the <key> field , calculates the proportion that each

row makes up out of the total of all rows in the group, and inserts

the proportion as a new field immediately following the key field.

Example 1

(Original Data:data) Shop Date Sold_Qty Cust_Qty

$ cat data

aShop Day1 103  62

bShop Day1 211 113

cShop Day1 81   52

dShop Day1 75   48

eShop Day1 210 140

Calculates proportion of Sold_Qty (3rd Field) for each shop and inserts it

after Sold_Qty.

$ proportion val=3 data | fcols

aShop Day1 103  75.7 62

bShop Day1 211 155.1 113

cShop Day1  81 59.6 52

dShop Day1  75 55.1 48

eShop Day1 210 154.4 140

               ^^^^^ Proportion Field

Example 2 "key" Option

Calculates the proportion of each record within a group of records who share

the same value in the <key> field.

The file must be sorted on the key field.

(Original Data:data2) Shop Date Sold_Qty Cust_Qty

$ cat data2

aShop Day1 103  62

aShop Day2 157  94

aShop Day3  62 30

bShop Day1 211 113

bShop Day2 237 121

bShop Day3 150  82

cShop Day1  81 52

cShop Day2  76 49

cShop Day3  38 21

dShop Day1  75 48

dShop Day2  72 42

dShop Day3  34 19

eShop Day1 210 140

eShop Day2 149  91

eShop Day3 120  73

Calculates proportion of Sold_Qty for each shop for each day (Field 2).

$ msort key=2/1 data2 | proportion key=2 val=3 | fcols

aShop Day1 103  75.7 62

bShop Day1 211 155.1 113

cShop Day1  81 59.6 52

dShop Day1  75 55.1 48

eShop Day1 210 154.4 140

aShop Day2 157 113.6  94

bShop Day2 237 171.5 121

cShop Day2  76 55.0 49

dShop Day2  72 52.1 42

eShop Day2 149 107.8  91

aShop Day3  62 76.7 30

bShop Day3 150 185.6  82

cShop Day3  38 47.0 21

dShop Day3  34 42.1 19

eShop Day3 120 148.5  73

  ----

   |

   | Proportion on Day1

   |

  ----

  ----

   |

   | Proportion on Day2

   |

  ----

  ----

   |

   | Proportion on Day3

   |

  ----

               ^^^^^ Proportion Field

Example 3 "+h" Option

The "+<n>h" option will skip the first <n> records in the file. This

is useful when the first line is a header line. The header for the

proportion field that is inserted is "@".

(Original Data:data3)

$ cat data

Shop Date Sold_Qty Cust_Qty   <- Header Line

aShop Day1 103  62

bShop Day1 211 113

cShop Day1  81 52

dShop Day1  75 48

eShop Day1 210 140

Skipping the first line, Calculates proportion of Sold_Qty (3rd

Field) for each shop and inserts it after Sold_Qty.

$ proportion +h val=3 data3 | fcols

 Shop Date Sold_Qty     @ Cust_Qty   <- "@" is inserted at added field

aShop Day1      103  75.7      62

bShop Day1      211 155.1      113

cShop Day1       81  59.6      52

dShop Day1       75  55.1      48

eShop Day1      210 154.4      140

                    ^^^^^ Proportion Field

Example 4 "-<p>" Option

The -<p> option lets you set the decimal precision of the proportion.

Calculates proportion of Sold_Qty (3rd Field) for each shop out to

three decimal places.

$ proportion -3 val=3 data | fcols

aShop Day1 103  75.735 62

bShop Day1 211 155.147 113

cShop Day1  81 59.559 52

dShop Day1  75 55.147 48

eShop Day1 210 154.412 140

Example 5 Compensation option

Sums of proportion may not be 100.0 * #_of_records because of the

rounding. Compensation option forces sums of proportion to

100.0 * #_of_records by adding the difference to a record. The record

to which adding the difference is:

--first   the first record

--last    the last record

--max     the maximum value record

--min     the minimum value record

--auto    the maximum value record or the minimum value record

          depending on the sign of the difference

$ proportion --first val=3 data | fcols

aShop Day1 103  75.8 62   <- compensated record

bShop Day1 211 155.1 113

cShop Day1  81 59.6 52

dShop Day1  75 55.1 48

eShop Day1 210 154.4 140

$ proportion --last val=3 data | fcols

aShop Day1 103  75.7 62

bShop Day1 211 155.1 113

cShop Day1  81 59.6 52

dShop Day1  75 55.1 48

eShop Day1 210 154.5 140   <- compensated record

$ proportion --max val=3 data | fcols

aShop Day1 103  75.7 62

bShop Day1 211 155.2 113   <- compensated record

cShop Day1  81 59.6 52

dShop Day1  75 55.1 48

eShop Day1 210 154.4 140

$ proportion --min val=3 data | fcols

aShop Day1 103  75.7 62

bShop Day1 211 155.1 113

cShop Day1  81 59.6 52

dShop Day1  75 55.2 48   <- compensated record

eShop Day1 210 154.4 140

$ proportion --auto val=3 data | fcols

aShop Day1 103  75.7 62

bShop Day1 211 155.2 113   <- compensated record

cShop Day1  81 59.6 52

dShop Day1  75 55.1 48

eShop Day1 210 154.4 140

(Note)

The old syntax is "proportion [ref=<ref>] key=<key> <file>"

This old syntax won't be supported in the near future.

(See Also)

ratio(USP)