【问题标题】:Conditional transform for XDF fileXDF 文件的条件转换
【发布时间】:2017-07-15 00:34:56
【问题描述】:

我在 Microsoft R 中有一个 XDF 文件。这是我的问题的简化版本。它有 2 列,其中 1 列是分类的,包含索引,如“1”、“2”、“3”等……一直到“10”。第二列是数字。我想做的是创建一个 3 列,即第二列的转换,但以第一列为条件。即,类似

if col1 == '1' then col3 = col2*0.50 else if col2 == '2' then col3 = col2*0.80

等等。

我知道你可以直接在 R 中进行转换,但我不知道如何完成这样的事情。

【问题讨论】:

    标签: r microsoft-r


    【解决方案1】:

    这行得通吗?

    MyDataset <- RxXdfData("./path/dataset.xdf") #the dataset you are using
    
    # replace transFormedCol with the name of the col you want to use 
    rxDataStep(inData = MyDataset,
               outFile = MyDataset,
               transforms = list(
                 transFormedCol = ifelse(col1 == '1',col2*0.5,
                                         ifelse(col2 == '2', col2*0.8))), #etc...
               overwrite = TRUE
               )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多