# NOT RUN {
# Dataframe used throughout this doc
df <- createDataFrame(cbind(model = rownames(mtcars), mtcars))
# }
# NOT RUN {
# }
# NOT RUN {
tmp <- mutate(df, v1 = lit(df$mpg), v2 = lit("x"), v3 = lit("2015-01-01"),
v4 = negate(df$mpg), v5 = expr('length(model)'),
v6 = greatest(df$vs, df$am), v7 = least(df$vs, df$am),
v8 = column("mpg"))
head(tmp)
# }
# NOT RUN {
# }
# NOT RUN {
head(select(df, bitwiseNOT(cast(df$vs, "int"))))
# }
# NOT RUN {
# }
# NOT RUN {
head(select(df, monotonically_increasing_id()))
# }
# NOT RUN {
# }
# NOT RUN {
head(select(df, spark_partition_id()))
# }
# NOT RUN {
# }
# NOT RUN {
tmp <- mutate(df, v1 = struct(df$mpg, df$cyl), v2 = struct("hp", "wt", "vs"),
v3 = create_array(df$mpg, df$cyl, df$hp),
v4 = create_map(lit("x"), lit(1.0), lit("y"), lit(-1.0)))
head(tmp)
# }
# NOT RUN {
# }
# NOT RUN {
tmp <- mutate(df, r1 = rand(), r2 = rand(10), r3 = randn(), r4 = randn(10))
head(tmp)
# }
# NOT RUN {
# }
# NOT RUN {
tmp <- mutate(df, mpg_na = otherwise(when(df$mpg > 20, df$mpg), lit(NaN)),
mpg2 = ifelse(df$mpg > 20 & df$am > 0, 0, 1),
mpg3 = ifelse(df$mpg > 20, df$mpg, 20.0))
head(tmp)
tmp <- mutate(tmp, ind_na1 = is.nan(tmp$mpg_na), ind_na2 = isnan(tmp$mpg_na))
head(select(tmp, coalesce(tmp$mpg_na, tmp$mpg)))
head(select(tmp, nanvl(tmp$mpg_na, tmp$hp)))
# }
# NOT RUN {
# }
# NOT RUN {
tmp <- read.text("README.md")
head(select(tmp, input_file_name()))
# }
Run the code above in your browser using DataLab