# NOT RUN {
# Columns can be selected using [[ and [
df[[2]] == df[["age"]]
df[,2] == df[,"age"]
df[,c("name", "age")]
# Or to filter rows
df[df$age > 20,]
# SparkDataFrame can be subset on both rows and Columns
df[df$name == "Smith", c(1,2)]
df[df$age %in% c(19, 30), 1:2]
subset(df, df$age %in% c(19, 30), 1:2)
subset(df, df$age %in% c(19), select = c(1,2))
subset(df, select = c(1,2))
# Columns can be selected and set
df[["age"]] <- 23
df[[1]] <- df$age
df[[2]] <- NULL # drop column
# }
Run the code above in your browser using DataLab