當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R SparkR dropFields用法及代碼示例

說明:

按名稱刪除結構Column 中的字段。

用法:

dropFields(x, ...)

## S4 method for signature 'Column'
dropFields(x, ...)

參數:

  • x 一列
  • ... 要刪除的字段的名稱。

注意:

從 3.1.0 開始的 dropFields

例子:

df <- select(
  createDataFrame(iris),
  alias(
    struct(
      column("Sepal_Width"), column("Sepal_Length"),
      alias(
        struct(
          column("Petal_Width"), column("Petal_Length"),
          alias(
            column("Petal_Width") * column("Petal_Length"),
            "Petal_Product"
          )
        ),
        "Petal"
      )
    ),
    "dimensions"
  )
)
head(withColumn(df, "dimensions", dropFields(df$dimensions, "Petal")))

head(
  withColumn(
    df, "dimensions",
    dropFields(df$dimensions, "Sepal_Width", "Sepal_Length")
  )
)

# This method supports dropping multiple nested fields directly e.g.
head(
  withColumn(
    df, "dimensions",
    dropFields(df$dimensions, "Petal.Petal_Width", "Petal.Petal_Length")
  )
)

# However, if you are going to add/replace multiple nested fields,
# it is preferred to extract out the nested struct before
# adding/replacing multiple fields e.g.
head(
  withColumn(
    df, "dimensions",
    withField(
      column("dimensions"),
      "Petal",
      dropFields(column("dimensions.Petal"), "Petal_Width", "Petal_Length")
    )
  )
)

相關用法


注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 dropFields。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。