' Name: Table.RowStatistics ' ' Title: Calculates statistics for all values (but the first) in selected row(s) from the active table ' ' Topics: Tables, Spatial Analyst ' ' Description: Calculates statistics of all values (but the first) in a row, which is ' useful after crosstabulation of areas like: Analysis | Tabulate Areas (Spatial Analyst) ' where you end up with a table for instance with 10 regions (classes) and corresponding landuse: ' ' class | urban_area | agri_area | wood_area ' 1 | 2000 | 2400 | 40000 ' ' The result is a MessageBox.Report with statistics for each selected row. ' ' Requires: A table must be the active document.You have to select row(s) to run the statistics. ' ' Author: Daniel Schwandt, July 2000 ' ' Self: ' ' Returns: ' theTable = av.GetActiveDoc theVTab = theTable.GetVTab thePrecision = "d.ddddd" Script.The.SetNumberFormat( thePrecision ) if ( theVTab.GetSelection.Count = 0 ) then 'theSet = theVTab MsgBox.Info ("Please select the row(s) you want calculate statistics for !", "No Row(s) selected") return nil else theSet = theVTab.GetSelection end theFields = theVTab.GetFields vfld = theFields.Get(0) 'stats over all values (but the first) of a record (a row) for each record in theSet summe = 0 count = 0 theSumSqDev = 0 theMinimum = nil theMaximum = nil for each f in theVTab.GetFields if ((f = vfld ).not) then v = theVTab.ReturnValue(f, record) if ( not ( v.IsNull ) ) then if ( theMinimum = nil ) then theMinimum = v theMaximum = v else theMinimum = theMinimum min v theMaximum = theMaximum max v end end summe = summe + v count = count + 1 end end theMean = summe / count for each f in theVTab.GetFields if ((f = vfld ).not) then vv = theVTab.ReturnValue(f, record) if ( not ( vv.IsNull ) ) then theSqDev = ( vv - theMean ) * ( vv - theMean ) theSumSqDev = theSqDev + theSumSqDev end end end if (count > 1) then theVariance = theSumsqdev / (count - 1) theStdDev = theVariance.Sqrt else theVariance = 0 theStdDev = 0 end MsgBox.Report( "Sum: " + summe.AsString + nl + "Count: " + count.SetFormat( "d" ).AsString + nl + "Mean: " + theMean.AsString + nl + "Maximum: " + theMaximum.AsString + nl + "Minimum: " + theMinimum.AsString + nl + "Range: " + ( theMaximum-theMinimum ).Abs.AsString +nl+ "Variance: " + theVariance.AsString + nl + "Standard Deviation: " + theStdDev.AsString, "Row-Statistics for" ++ vfld.GetAlias ++ theVTab.ReturnValue(vfld, record).SetFormatPrecision(vfld.getprecision).asString ) end