Description Usage Arguments Note Examples
Drops fields in a struct Column
by name.
1 2 3 4 | dropFields(x, ...)
## S4 method for signature 'Column'
dropFields(x, ...)
|
x |
a Column |
... |
names of the fields to be dropped. |
dropFields since 3.1.0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | ## Not run:
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")
)
)
)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.