eval - R lazy evaluation of two variables in data.frame -


given 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 expression captured lazy() argument in lazyeval package

library(lazyeval) toeval <- lazy(c(a,b)) 

i want data frame 2 variables , b instead of 1 concatenated vector, given with

result <- lazy_eval(toeval, df) 

an unelegant version instantly comes ones mind

df_result <- data.frame(a = result[1:(nrow(df))],                         b = result[(nrow(df)+1):(nrow(df)*2)]) 

better ideas appreciated!

you can try:

toeval <- lazy(list(a,b)) data.frame(do.call(cbind, lazy_eval(toeval, df))) 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -