Given a data frame
df <- data.frame(a = sample(c(1,0), 30, replace = TRUE),
b = sample(c(2,3), 30, replace = TRUE),
c = sample(c(4,5), 30, replace = TRUE))
and an expression captured by the lazy()
argument in the lazyeval
package
library(lazyeval)
toeval <- lazy(c(a,b))
I want to get a data frame with those two variables a and b instead of one concatenated vector, as given with
result <- lazy_eval(toeval, df)
An unelegant version instantly comes to ones mind
df_result <- data.frame(a = result[1:(nrow(df))],
b = result[(nrow(df)+1):(nrow(df)*2)])
Better ideas are very much appreciated!