make_df: Turn objects into data frames

Description Usage Arguments Author(s) Examples

View source: R/make_df.r

Description

Some R functionality (I'm thinking mainly of ggplot2) requires the data you are interested in to be packaged in data frames, hence this function.

Usage

1
make_df(object, env, ...)

Arguments

object

an object

env

an environment

...

passed arguments

Author(s)

Henrik Renlund

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# combine variables into a data frame
x <- 1:2
y <- letters[1:2]
make_df(c("x","y"))
# 'env' is R_GlobalEnv by default but can be any environment, data frame or list
make_df(c("mpg", "disp"), env=datasets::mtcars)
# methods include 'list' ...
make_df(list(x=1:2, y=letters[1:2]))
# and 'survfit'
if(FALSE){
  n <- 50
  s <- survival::Surv(rexp(n), rbinom(n,1,0.2))
  f <- factor(rep(letters[1:2], length.out=n))
  sf <- survival::survfit(s~f)
  make_df(sf)
}

renlund/dataman documentation built on March 19, 2018, 10:09 a.m.