r - Generate an accumulated array of strings from a string array -
i have this:
str <- c("var1", "var2", "var3")
and want generate following array of strings:
"c ~ var1" "c ~ var1 + var2" "c ~ var1 + var2 + var3"
i know can hardcode this, since there 3 strings, want method vector of size. there simple way achieve this?
you try this:
out <- vector() out[1] <- paste("c ~",str[1]) (i in 2:length(str)) out[i] <- paste(out[i-1], "+", str[i])
Comments
Post a Comment