0
我想通过使用原始列相互减去创建新列,我用字符来表达所有新列的组合,然后我想用dplyr::mutate
来创建新的列。 foo <- eval(parse(text = paste(new.feature,collapse = ",")))
有问题,谢谢你的回答。有关使用字符串作为函数参数在R
col.names <- names(iris)
sign.paste <- function(x){paste(x,collapse = "-")}
new.feature <- apply(combn(col.names,2),2,sign.paste)
paste(new.feature,collapse = ",")
foo <- eval(parse(text = paste(new.feature,collapse = ",")))
dplyr::mutate(iris,foo)
当我使用paste(new.feature,collapse = ",")
,我会得到这样的
paste(new.feature,collapse = ",")
[1]“Sepal.Length-Sepal.Width,Sepal.Length-Petal.Length,Sepal.Length字符-Petal.Width,Sepal.Length品种,Sepal.Width-Petal.Length,Sepal.Width-Petal.Width,Sepal.Width品种,Petal.Length-Petal.Width,Petal.Length品种,Petal.Width “物种”
终于,我想我们e mutate
创建新列,但失败..