Learn R Programming

SparkR (version 2.1.2)

select: Select

Description

Selects a set of columns with names or Column expressions.

Usage

select(x, col, ...)

# S4 method for SparkDataFrame $(x, name)

# S4 method for SparkDataFrame $(x, name) <- value

# S4 method for SparkDataFrame,character select(x, col, ...)

# S4 method for SparkDataFrame,Column select(x, col, ...)

# S4 method for SparkDataFrame,list select(x, col)

Arguments

x

a SparkDataFrame.

col

a list of columns or single Column or name.

...

additional column(s) if only one column is specified in col. If more than one column is assigned in col, ... should be left empty.

name

name of a Column (without being wrapped by "").

value

a Column or an atomic vector in the length of 1 as literal value, or NULL. If NULL, the specified Column is dropped.

Value

A new SparkDataFrame with selected columns.

See Also

Other SparkDataFrame functions: SparkDataFrame-class, agg, arrange, as.data.frame, attach, cache, coalesce, collect, colnames, coltypes, createOrReplaceTempView, crossJoin, dapplyCollect, dapply, describe, dim, distinct, dropDuplicates, dropna, drop, dtypes, except, explain, filter, first, gapplyCollect, gapply, getNumPartitions, group_by, head, histogram, insertInto, intersect, isLocal, join, limit, merge, mutate, ncol, nrow, persist, printSchema, randomSplit, rbind, registerTempTable, rename, repartition, sample, saveAsTable, schema, selectExpr, showDF, show, storageLevel, str, subset, take, union, unpersist, withColumn, with, write.df, write.jdbc, write.json, write.orc, write.parquet, write.text

Other subsetting functions: filter, subset

Examples

Run this code
# NOT RUN {
  select(df, "*")
  select(df, "col1", "col2")
  select(df, df$name, df$age + 1)
  select(df, c("col1", "col2"))
  select(df, list(df$name, df$age + 1))
  # Similar to R data frames columns can also be selected using $
  df[,df$age]
# }

Run the code above in your browser using DataLab