【问题标题】:How to create categorial variable based on continuous variable in Statsoft Statistica如何在 Statsoft Statistica 中基于连续变量创建分类变量
【发布时间】:2019-11-05 15:57:08
【问题描述】:

我正在对 Statistica 中的天气数据进行一些分析。其中一个变量是 wind direction,它是一个范围从 0 到 360 的连续变量。现在我想创建一个新列,将 winddirection 分为 8 个类别。

0-45: 'E'
45-90: 'NE'
90-135: 'N'

我需要使用自定义公式来生成这个新变量。 Case 声明将是理想的,但看起来这不是 Statistica 中的选项。 If..else 也可以,但 Statistica 有 iif 而不是纯 if。这样做的正确方法是什么?

【问题讨论】:

    标签: statistica


    【解决方案1】:

    IDK 您对宏的使用程度如何,但以下 SVB 宏可以重新编码一列。您必须提供源列和目标列。此宏假定源的值在 0 - 359 度之间。

    '#Language "WWB-COM"
    Option Base 1
    Option Explicit
    
    Sub Main
    
        Dim ss As Spreadsheet
        Set ss = ActiveSpreadsheet
    
        Dim SourceCol As Long
        Dim DestCol As Long
    
        SourceCol = 1
        DestCol = 3
    
    
        Dim MDValue
        MDValue = Option.Spreadsheet.DefaultMissingDataValue
    
        Dim i
        For i = 1 To ss.NumberOfCases
    
            Dim TheValue, NewValue
            TheValue = ss.Value(i, SourceCol)
            NewValue = MDValue
    
    
            If TheValue < 22.5 Then
                NewValue = "E"
            ElseIf TheValue < 67.5 Then
                NewValue = "NE"
            ElseIf TheValue < 112.5 Then
                NewValue = "N"
            ElseIf TheValue < 157.5 Then
                NewValue = "NW"
            ElseIf TheValue < 202.5 Then
                NewValue = "W"
            ElseIf TheValue < 247.5 Then
                NewValue = "SW"
            ElseIf TheValue < 292.5 Then
                NewValue = "S"
            ElseIf TheValue < 337.5 Then
                NewValue = "SE"
            Else
                NewValue = "E"
            End If
    
            ss.Value(i, DestCol) = NewValue
        Next
    
    End Sub
    

    【讨论】:

    • 您也可以使用重新编码对话框,它有 256 个条件,您可以使用这些条件重新编码变量。
    猜你喜欢
    • 1970-01-01
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-02
    • 2019-11-24
    • 2018-01-21
    • 2020-09-16
    相关资源
    最近更新 更多