I want to create new columns by using the original columns subtract each other, I use character to express all the combination of new columns, then I want to usedplyr::mutate
to create new columns. There are something wrong in foo <- eval(parse(text = paste(new.feature,collapse = ",")))
, thank you for your answer.
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)
when I use paste(new.feature,collapse = ",")
, I will get a character like these
paste(new.feature,collapse = ",")
[1] "Sepal.Length-Sepal.Width,Sepal.Length-Petal.Length,Sepal.Length-Petal.Width,Sepal.Length-Species,Sepal.Width-Petal.Length,Sepal.Width-Petal.Width,Sepal.Width-Species,Petal.Length-Petal.Width,Petal.Length-Species,Petal.Width-Species"
Finally, I want to usemutate
to create new columns, but failed..