SparkR:如何合并多个“;什么时候/&引用;否则";多种条件

SparkR:如何合并多个“;什么时候/&引用;否则";多种条件,r,apache-spark,apache-spark-sql,sparkr,R,Apache Spark,Apache Spark Sql,Sparkr,我试图在base a multiple conditions中创建一个新列,但我发现我不能使用只有一个Other的multiple when子句,我不得不使用如下内容: test1 <- test %>% withColumn("newCol1", otherwise(when(column("oldCol1") == 1, lit("one")),

我试图在base a multiple conditions中创建一个新列,但我发现我不能使用只有一个Other的multiple when子句,我不得不使用如下内容:

 test1 <- test %>%  withColumn("newCol1", otherwise(when(column("oldCol1") == 1, lit("one")), 
                                                    otherwise(when(column("oldCol1") == 2,lit("two")),
                                                              lit("other")))) %>%
  select(column("oldCol1"), column("newCol1"))

SparkR中的WHEN函数是否有更清晰的使用方法?

您可以尝试
合并
-ing
WHEN
语句:

test1 <- test %>% withColumn(
    "newCol1", 
    coalesce(
        when(column("oldCol1") == 1, lit("one")),
        when(column("oldCol1") == 2, lit("two")),
        lit("other")
    )
) %>% select(column("oldCol1"), column("newCol1"))
test1%withColumn(
“newCol1”,
结合(
当(列(“oldCol1”)==1时,点亮(“一”),
当(列(“oldCol1”)==2时,点亮(“两”),
lit(“其他”)
)
)%%>%选择(列(“旧列1”)、列(“新列1”))
test1 <- test %>% withColumn(
    "newCol1", 
    coalesce(
        when(column("oldCol1") == 1, lit("one")),
        when(column("oldCol1") == 2, lit("two")),
        lit("other")
    )
) %>% select(column("oldCol1"), column("newCol1"))