在以下示例中,变量expr
包含字符串形式的表达式。但是,最后一个mutate
命令不能正确评估该表达式。你能帮我理解为什么吗?
symbols <- expand.grid(data.frame(matrix(rep(c("+","-",""),8),ncol=8)))
df <- symbols %>%
transmute(expr=paste0(1,X1,2,X2,3,X3,4,X4,5,X5,6,X6,7,X7,8,X8,9)) %>%
mutate(eval=eval(parse(text=expr)))
答案 0 :(得分:2)
尝试rowwise()
df <- symbols %>%
transmute(expr=paste0(1,X1,2,X2,3,X3,4,X4,5,X5,6,X6,7,X7,8,X8,9)) %>%
rowwise() %>%
mutate(v1=eval(parse(text=expr)))