R vector calculate incorrect zscore

38 views Asked by At

I have a dataset like the following:

> Pricing
   ID Paper Type Weight Quantity Unit.quote.price Total.quote.price Material.cost
1   1  SRA3    2      1        1         2.600000           2.60000       0.04104
2   2  SRA3    2      1        2         2.600000           5.20000       0.04104
3   3  SRA3    2      1        3         2.600000           7.80000       0.04104
4   4  SRA3    2      1        4         2.600000          10.40000       0.04104
5   5  SRA3    2      1        5         2.600000          13.00000       0.04104
6   6  SRA3    2      1        6         2.600000          15.60000       0.04104

I've calculated the mean and sd for this dataset, which are

> mean
                Type               Weight             Quantity     Unit.quote.price 
        1.454545e+00         3.636364e+00         2.500500e+03         7.815069e-01 
   Total.quote.price        Material.cost        Machine.price      Material.factor 
        1.538275e+03         8.483818e-02         1.545455e-01         4.900000e+01 
      Machine.factor Meter.reading.charge           Fix.charge             Discount 
        5.890400e+00         7.727273e-02         7.727273e-02         1.542216e-01 
        Total.Profit          Unit.profit 
        9.396966e+02         5.421233e-01 
> sd <- apply(Pricing[,3:16],2, sd)
> sd
                Type               Weight             Quantity     Unit.quote.price 
        4.979341e-01         1.720096e+00         1.443389e+03         5.671822e-01 
   Total.quote.price        Material.cost        Machine.price      Material.factor 
        9.600757e+02         4.462600e-02         4.979341e-02         0.000000e+00 
      Machine.factor Meter.reading.charge           Fix.charge             Discount 
        0.000000e+00         2.489671e-02         2.489671e-02         8.406364e-02 
        Total.Profit          Unit.profit 
        6.839202e+02         5.476514e-01

But when I tried to calculate the score for this dataset, it outputs the incorrect result

> zscore <- (Pricing[,3:16]-mean)/sd
> zscore
         Type     Weight    Quantity Unit.quote.price Total.quote.price Material.cost
1   1.0954352       -Inf   -1.731689      101.3277520         -1.599536    -1.3739256
2  -0.9513209 37.0622228    2.148327       29.0943682        114.622917    -0.9149677
3  -1.7309959 37.0622228   -1.599119       -1.3701840        153.543494    -2.8387399
4   2.1483273 10.0611683   87.732761        3.7576400              -Inf    -2.0901873
5  -1.6001606 -1.3725235   97.311156        2.3004138               Inf    -1.7323531

For example, for the first row of column Weight, the zscore should be

> (Pricing[1,4] - 3.636364e+00)/1.720096e+00   
[1] -1.532684

Rather than '-Inf'. Please help.

0

There are 0 answers